Although it is possible to check for a ListBox's doubleclick event by setting a g-label and checking A_GuiEvent for "DoubleClick", the method isn't fully reliable. There are two shortcomings (not due to AHK, but due to the fact that doubleclick events in ListBoxes rely on the LBN_DBLCLK notification which purposely lacks those features):
1 - If there are no items in the ListBox, no event will be fired upon doubleclicking
2 - If an item is already selected in the ListBox, there are no distinctions between clicking on the item, and off of it (in an empty area)
I made a little script that allows you to make those distinctions.
How to use/add to your code
You need to set the
handle variable when creating the ListBox (by adding the option hwnd[name of variable] when using Gui, Add). You also need to add
OnMessage(515, "OnDblClick"). And finally, you need the whole function
OnDblClick from the script below (as well as setting up the labels to call for each possibility).
Code:
Gui, Add, ListBox, hwndhLB, This is a listbox item
OnMessage(515, "OnDblClick") ;Intercept WM_LBUTTONDBLCLK notifications
Gui, Show
Return
GuiClose:
ExitApp
OnDblClick(wParam, lParam, msg, hwnd) {
;Make the var global so that we can access it
Global hLB
;Make sure the notification comes from the listbox
If (hwnd = hLB) {
;Get item count. 395 = LB_GETCOUNT
SendMessage 395, 0, 0,, ahk_id %hwnd%
iCount := ErrorLevel
;Check for error
If (ErrorLevel = 0xFFFFFFFF)
Return
;Get the bottom edge of the last item. 408 = LB_GETITEMRECT
VarSetCapacity(uRect, 16, 0)
SendMessage 408, iCount - 1, &uRect,, ahk_id %hLB% ;%
iBottomEdge := (ErrorLevel <> 0xFFFFFFFF) ? NumGet(uRect, 12) : 0
;Extract the Y coordinate of the mouse click from lParam (high word)
iY := lParam >> 16
;Check if mouse click is under or over bottom edge
If (iY > iBottomEdge)
GoSub ListBoxDoubleClickOffItem ;The dblclick was off an item
Else
GoSub ListBoxDoubleClickOnItem ;The dblclick was on an item
}
}
ListBoxDoubleClickOnItem:
MsgBox You double-clicked on an item!
Return
ListBoxDoubleClickOffItem:
MsgBox You double-clicked off an item!
Return
Enjoy!