From 1f460f7ebc10c2f8bb66ae684498f49187eab9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 23 Oct 2020 01:44:02 +0200 Subject: first commit --- tt.doubleclick.ahk | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tt.doubleclick.ahk (limited to 'tt.doubleclick.ahk') diff --git a/tt.doubleclick.ahk b/tt.doubleclick.ahk new file mode 100644 index 0000000..0b2454b --- /dev/null +++ b/tt.doubleclick.ahk @@ -0,0 +1,94 @@ +;; DoubleClick function +;; ============================================================================ + +;; DoubleClick returns true if a double click has been performed. The first +;; click in the double click is allowed to pass through, but the second click +;; is prevented. + +;; To use the function, call it whenever the user clicks. The function returns +;; true if two calls in a row meet the requirements for a double click. + +;; Function definition -> library +;; ---------------------------------------------------------------------------- + +;; The 'alternate' argument, if set to true, signifies a right click: + +DoubleClick(alternate := false) +{ + +;; A bunch of global variables are needed to determine whether a double click +;; has been performed: + + global DoubleClickClicked + global DoubleClickPriorX + global DoubleClickPriorY + global DoubleClickLast + +;; The DoubleClickClicked variable should be set to false in the beginning of +;; the script: -> init + +DoubleClickClicked := false + +;; We'll continue the definition of the function. -> library + +;; The maximum double click area (x * y) and time (in milliseconds) are +;; retrieved from Windows: + + SysGet, SM_CXDOUBLECLK, 36 + SysGet, SM_CYDOUBLECLK, 37 + max := DllCall("User32\GetDoubleClickTime") + +;; The current absolute position of the mouse is retrieved: + + tmp := A_CoordModeMouse + CoordMode, Mouse, Screen + MouseGetPos, x, y + CoordMode, Mouse, %tmp% + +;; The DoubleClickClicked variable, if true, signifies that a first click has +;; already been performed. If false, a double click has not been initiated. + +;; If a click has not already been performed, then this is the first click. +;; The first click should be allowed to pass through, but the function takes +;; note of the click and sets the global variables against which to compare +;; the next click: + + if (not DoubleClickClicked) + { + if (alternate) + SendInput, {Click, right} + else + SendInput, {Click} + DoubleClickPriorX := x + DoubleClickPriorY := y + DoubleClickLast := A_TickCount + DoubleClickClicked := true + return false + } + +;; At this point, the function has been called for the second time, signifying +;; a second click. Now, it checks whether the two clicks meet the operating +;; system's requirements for a double click; if not, then this click is treated +;; as yet another first click: + + if (A_TickCount - DoubleClickLast > max + || abs(x - DoubleClickPriorX) > SM_CXDOUBLECLK + || abs(y - DoubleClickPriorY) > SM_CYDOUBLECLK) + { + if (alternate) + SendInput, {Click, right} + else + SendInput, {Click} + DoubleClickPriorX := x + DoubleClickPriorY := y + DoubleClickLast := A_TickCount + DoubleClickClicked := true + return false + } + +;; At this point, a double click has successfully been performed. The variable +;; signifying a first click is reset to false, and the function returns true: + + DoubleClickClicked := false + return true +} -- cgit v1.2.3