List selection by double click - How? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kdaube
Posts: 86
Joined: 02 Nov 2015, 03:11

List selection by double click - How?

Post by kdaube » 30 Jan 2023, 13:00

Dear experts,
Since in a long list a single click on the list items is common to indicate where I am when scrolling, i want to select the item by double click.
In the case at hand the selection should report the location aka index in the list - not the item contents.
But I struggle with with detection of the double click and with the index ...

Code: Select all

; this is not working as expected
listTLBLbl  := "Quick Access|Text formatting|Table formatting|Paragraphs|Object align|Object props|ETB_Extra|..."

Gui Add, ListBox, x020 y050 w200 h200   AltSubmit gFnSelTLB  vTLBCurrent,  %listTLBLbl%
GUI Show

FnSelTLB() { ; ------------------------------- Select from tool bar list --------------------------
  Gui Submit, noHide                                        ; get the varaible content
  If (A_GuiEvent == DoubleClick) {
    MsgBox Double click detected for %TLBCurrent%               ; selection position
  }
}
Klaus Daube, Zürich, CH

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: List selection by double click - How?

Post by garry » 30 Jan 2023, 13:31

example

DOUBLE-CLICK

Code: Select all

listTLBLbl  := "Quick Access|Text formatting|Table formatting|Paragraphs|Object align|Object props|ETB_Extra|..."
Gui Add, ListBox, x020 y050 w200 h200   gFnSelTLB  vTLBCurrent,  %listTLBLbl%
GUI Show
return
;-----
Guiclose:
Exitapp
FnSelTLB() { ; ------------------------------- Select from tool bar list --------------------------
  If (A_GuiEvent ="DoubleClick") {
     GuiControlGet,TLBCurrent
    MsgBox Double click detected for %TLBCurrent%               ; selection position
  }
}
OR ONCE-CLICK / DOUBLE-CLICK

Code: Select all

listTLBLbl  := "Quick Access|Text formatting|Table formatting|Paragraphs|Object align|Object props|ETB_Extra|..."
Gui Add, ListBox, x020 y050 w200 h200  gFnSelTLB  vTLBCurrent ,  %listTLBLbl%
GUI Show
return
Guiclose:
Exitapp
;--------
FnSelTLB:
Gui,1:submit,nohide
event := A_GuiEvent
SetTimer,NextLB, -200
Return
;------
NextLB:
If (event = "Normal")
 MsgBox Normal clicked  %TLBCurrent%
If (event = "DoubleClick")
 MsgBox Double clicked %TLBCurrent%
Return
;========================================
; OR DOUBLE-CLICK / RIGHT-CLICK

Code: Select all

listTLBLbl  := "Quick Access|Text formatting|Table formatting|Paragraphs|Object align|Object props|ETB_Extra|..."
Gui Add, ListBox, x020 y050 w200 h200   gFnSelTLB  vTLBCurrent,  %listTLBLbl%
;Gui,add,text,w0 h0 vT1
GUI Show
return
Guiclose:
Exitapp
;--- doubleclick 
FnSelTLB() { ; ------------------------------- Select from tool bar list --------------------------
  If (A_GuiEvent ="DoubleClick") {
     GuiControlGet,TLBCurrent
    MsgBox,Double click detected for > %TLBCurrent%               ; selection position
	Guicontrol,1:choose,TLBCurrent,|8
  }
}
;---- RIGHTCLICK ---------
GuiContextMenu:
If (A_GuiControl = "TLBCurrent") && (A_GuiEvent = "RightCLick" )
  {
  click
  GuiControlGet,TLBCurrent
  if TLBCurrent<>
  msgbox,RightClick > %TLBCurrent%
  Guicontrol,1:choose,TLBCurrent,|8
 }
Return
;-------------------------
Last edited by garry on 30 Jan 2023, 14:17, edited 2 times in total.

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: List selection by double click - How?  Topic is solved

Post by mikeyww » 30 Jan 2023, 13:39

Code: Select all

#Requires AutoHotkey v1.1.33
Global TLBCurrent                ; Enables access to variable in function
list := "Quick Access|Text formatting|Table formatting|Paragraphs|Object align|Object props|ETB_Extra|..."
Gui Add, ListBox, h200 gact vTLBCurrent, % list
Gui Show

act() {
 Gui Submit, NoHide
 If (A_GuiEvent = "DoubleClick") ; Use expressions
  MsgBox Double click detected for %TLBCurrent%
}

User avatar
kdaube
Posts: 86
Joined: 02 Nov 2015, 03:11

Re: List selection by double click - How?

Post by kdaube » 30 Jan 2023, 14:36

Thank you, Garry and Mikey
I will test tomorrow. However, i thought that the single = sign is an assignment, not a compare operator:
If (A_GuiEvent = "DoubleClick") Is IMHO a syntax violation - a trap into which I felt lt very often.
Klaus Daube, Zürich, CH

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: List selection by double click - How?

Post by mikeyww » 30 Jan 2023, 14:43

A syntax violation is neither true here, nor would it reflect any type of opinion. A challenge of AHK v1 is indeed the ambiguity or, at the least, the duality of =, as it can be used as assignment in other circumstances. AHK v2 eliminates the use of = for all assignments.

If:
An If statement that contains an expression is usually differentiated from a traditional If statement such as if FoundColor != Blue by enclosing the expression in parentheses, as in if (FoundColor != "Blue"). However, this is not strictly required, as any If statement which does not match any of the legacy if patterns is assumed to contain an expression.

User avatar
kdaube
Posts: 86
Joined: 02 Nov 2015, 03:11

Re: List selection by double click - How?

Post by kdaube » 31 Jan 2023, 12:26

mikeyww, thank You for this explanation.
Although I have marked your post as accepted answer (I will implement this algogrithm), also that one of garry is of value - i will keep them in my samples collection.
Klaus Daube, Zürich, CH

Post Reply

Return to “Ask for Help (v1)”