Last active
June 12, 2018 08:59
-
-
Save jocutajar/a7d697312b038067d500842c0f3e74f1 to your computer and use it in GitHub Desktop.
AHK marble X*Y scroll emulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; Emulate_Scrolling_Middle_Button.ahk | |
;; Author: Erik Elmore <[email protected]> | |
;; Version: 1.1 (Aug 16, 2005) | |
;; | |
;; Enables you to use any key with cursor movement | |
;; to emulate a scrolling middle button. While | |
;; the TriggerKey is held down, you may move the | |
;; mouse cursor up and down to send scroll wheel | |
;; events. If the cursor does not move by the | |
;; time the TriggerKey is released, then a middle | |
;; button click is generated. I wrote this for my | |
;; 4-button Logitech Marble Mouse (trackball), | |
;; which has no middle button or scroll wheel. | |
;; | |
;; Configuration | |
;;#NoTrayIcon | |
;; Higher numbers mean less sensitivity | |
esmb_Threshold = 5 | |
;; This key/Button activates scrolling | |
esmb_TriggerKey = XButton1 | |
;; End of configuration | |
#Persistent | |
CoordMode, Mouse, Screen | |
Hotkey, *%esmb_TriggerKey%, esmb_TriggerKeyDown | |
HotKey, *%esmb_TriggerKey% Up, esmb_TriggerKeyUp | |
esmb_KeyDown = n | |
SetTimer, esmb_CheckForScrollEventAndExecute, 10 | |
return | |
esmb_TriggerKeyDown: | |
esmb_Moved = n | |
esmb_FirstIteration = y | |
esmb_KeyDown = y | |
MouseGetPos, esmb_OrigX, esmb_OrigY | |
esmb_XAccu = 0 | |
esmb_YAccu = 0 | |
return | |
esmb_TriggerKeyUp: | |
esmb_KeyDown = n | |
;; Send a middle-click if we did not scroll | |
if esmb_Moved = n | |
MouseClick, Middle | |
return | |
esmb_CheckForScrollEventAndExecute: | |
if esmb_KeyDown = n | |
return | |
MouseGetPos, esmb_X, esmb_Y | |
esmb_XAccu := esmb_XAccu + esmb_X - esmb_OrigX | |
esmb_YAccu := esmb_YAccu + esmb_Y - esmb_OrigY | |
if (esmb_XAccu or esmb_YAccu) | |
esmb_Moved = y | |
esmb_XScroll := (esmb_XAccu // esmb_Threshold) | |
esmb_YScroll := (esmb_YAccu // esmb_Threshold) | |
esmb_XAccu := esmb_XAccu - esmb_XScroll * esmb_Threshold | |
esmb_YAccu := esmb_YAccu - esmb_YScroll * esmb_Threshold | |
esmb_XDir := "WheelRight" | |
if (esmb_XScroll < 0) { | |
esmb_XDir := "WheelLeft" | |
esmb_XScroll := (-1 * esmb_XScroll) | |
} | |
esmb_YDir := "WheelDown" | |
if (esmb_YScroll < 0) { | |
esmb_YDir := "WheelUp" | |
esmb_YScroll := (-1 * esmb_YScroll) | |
} | |
;; Do not send clicks on the first iteration | |
if esmb_FirstIteration = y | |
esmb_FirstIteration = n | |
else { | |
Loop, %esmb_YScroll% { | |
MouseClick, %esmb_YDir% | |
} | |
Loop, %esmb_XScroll% { | |
MouseClick, %esmb_XDir% | |
} | |
} | |
MouseMove,esmb_OrigX,esmb_OrigY,0 | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment