A_GuiEvent

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
labrint
Posts: 383
Joined: 14 Jun 2017, 05:06
Location: Malta

A_GuiEvent

Post by labrint » 21 Nov 2019, 04:28

Consider the following function which controls listview tables.

Code: Select all

ListCtrlEvent(ctrlHwnd:=0, guiEvent:="", eventInfo:="", errLvl:="") {

	If A_GuiEvent
	LvSel := A_GuiControl

	GuiControlGet, ctrlName, Name, %CtrlHwnd%
	
	rownumber := eventInfo
	
	    If (guiEvent = "DoubleClick") {
	    	Thread, NoTimers , True
	;eventInfo ;event info is rownumber
	
	If ctrlName = MyFirstListView
	{
	Gui, ListView, MyFirstListView
	LV_GetText(Desc,eventInfo,1)
	LV_GetText(Qty,eventInfo,2)
	;Set of instructions
	    }
	    
	    If (guiEvent = "Normal") {
	    	Thread, NoTimers , True
			;eventInfo ;event info is rownumber
	If ctrlName = MyFirstListView
	{
	Gui, ListView, MyFirstListView
	LV_GetText(Desc,eventInfo,1)
	LV_GetText(Qty,eventInfo,2)
	    ;Set of instructions
	    }
	    
	  }
	    	   
Whenever I click on the row of the listview I get the guiEvent normal triggered, which is what I want, but when I double click, the guiEvent normal is overriding the doubleclick and I have to mouse click zillion times to get it to work. I tried to put in keywaits and the following code to distinguish between them

Code: Select all

If (A_TimeSincePriorHotkey<400) and (A_TimeSincePriorHotkey<>-1)
but nothing seems to work. I have used other guiEvents such as right click for other things therefore I cannot use them. I tried to use the mouseover function to get the hover to fill in but it was too memory intensive as it needs to persistently run. Please help
l6908lay
Posts: 43
Joined: 09 Apr 2023, 05:16

Re: A_GuiEvent

Post by l6908lay » 22 May 2024, 11:56

I don't believe there is a way to set a A_GuiEvent Timer (internally set by ahk/windows) so that it works to a particular amount of time. Which is what it looks like you're actually requesting. The internal function of A_GuiEvent is timed by the user input if you are slower than the internal time then the Doubleclick action just won't be registered (which I don't know what the internal time is). you can also place A_GuiEvent in a variable such as

Code: Select all

myeventhandler .= A_GuiEvent "`n"
This can be used to evaluate if double click is being registered with normal click. of course you will have to loop parse the event to see which event is happening. And also you'll need to clear the variable in particular intervals so that double click isn't held. for instance:

Code: Select all

myeventhandler .= A_GuiEvent "`n"
Loop, Parse, % myeventhandler, `n
	if (A_LoopField == "DoubleClick")
	{
		myeventhandler:= ""
		Thread, NoTimers , True
	}
You could also create your own click event with it's own respective timer involved. But that would require to "send" a variable at which the DoubleClick action should be invoked. something Like:

Code: Select all

if (thisClick == "")
	thisClick:= 0
if (thisClick == 2)
	thisClick:= 0
if (thisVariable == lastVariable)&&(thisClick == 2) ; of course it only makes sense that if thisVariable == lastVariable 
									;it is the second time it was clicked but you are requesting the click count. 
									;We're only using the variable to add to click or reset it.
{
	thisClick:= 0
	Thread, NoTimers , True
}
else
	thisClick++
;
;
;
lastvariable:=% thisVariable ; thisVariable is most likely the selection of the listview get. 
					 ; you possibly can get away with not even adding the clicks up but that also depends on how much the Click matters
					 ; and exactly what you plan to do with it.
Return
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: A_GuiEvent

Post by just me » 23 May 2024, 04:18

Each complete double-click consists of 4 mouse events:
  1. button down
  2. button up
  3. button doubleclick
  4. button up
That means that there is always a Normal event preceding the DoubleClick event.

If you want to igmore the Normal event in case of a following DoubleClick, you have to wait for the latter.

Code: Select all

#Requires AutoHotkey v1.1.34

Gui, Add, ListView, w400 r15 Grid AltSubmit gLVCtrlEvent, Column 1|Column 2|Column 3
Loop, 15
   LV_Add("", "Row" . A_Index . "_1",, "Row" . A_Index . "_2", "Row" . A_Index . "_3")
Gui, Show, , ListView
Return

GuiCLose:
ExitApp

LVCtrlEvent(CtrlHwnd := 0 , GuiEvent := "", EventInfo := "", ErrLvl := "") {
   Static DblClkTime := DllCall("GetDoubleClickTime", "UInt") + 16
   Switch GuiEvent {
      Case "Normal":       ; delayed processing
         LVEventTimer(Hwnd := CtrlHwnd, Row := EventInfo)
         SetTimer, LVEventTimer, -%DblClkTime%
      Case "DoubleClick":  ; double-click processing
         SetTimer, LVEventTimer, Off
         MsgBox, Double click!
      Case "SingleClick":  ; single-click processing
         MsgBox, Single click!
   }

}
LVEventTimer(Hwnd := 0, Row := "") {
   Static LVHwnd := 0, LVRow := 0
   If (Hwnd) {
      LVHwnd := Hwnd
      LVRow := Row
   }
   Else If (LVHwnd) {
      LVCtrlEvent(LVHwnd, "SingleClick", LVRow)
      LVHwnd := 0
   }
}

If you want to reliably get both events, try to add Critical at the start of your event function.
Post Reply

Return to “Ask for Help (v1)”