;; DoubleClick function ;; ============================================================================ ;; DoubleClick returns true if a double click has been performed. ;; 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 ;; ---------------------------------------------------------------------------- DoubleClick() { ;; 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) { 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) { 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 }