aboutsummaryrefslogtreecommitdiff
path: root/tt.doubleclick.ahk
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-10-23 01:44:02 +0200
committerJohn Ankarström <john@ankarstrom.se>2020-10-23 01:44:02 +0200
commit1f460f7ebc10c2f8bb66ae684498f49187eab9bc (patch)
tree776f7a92b0d24e27cd682e4ff76bde477a02ff98 /tt.doubleclick.ahk
downloadahk-1f460f7ebc10c2f8bb66ae684498f49187eab9bc.tar.gz
first commit
Diffstat (limited to 'tt.doubleclick.ahk')
-rw-r--r--tt.doubleclick.ahk94
1 files changed, 94 insertions, 0 deletions
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
+}