Skip to content

Instantly share code, notes, and snippets.

@Jerakin
Created October 9, 2019 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jerakin/5c6bd9b50f26348d28a1a995721e9fd1 to your computer and use it in GitHub Desktop.
Save Jerakin/5c6bd9b50f26348d28a1a995721e9fd1 to your computer and use it in GitHub Desktop.
Enables you to use any key with cursor movement to emulate a scrolling middle button. Written for Trackball mice.
;;
;; Emulate_Scrolling_Middle_Button.ahk
;; Author: Erik Elmore <erik@ironsavior.net>
;; 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 = 15
;; 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_AccumulatedDistance = 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_NewY
esmb_Distance := esmb_NewY - esmb_OrigY
if esmb_Distance
esmb_Moved = y
esmb_AccumulatedDistance := (esmb_AccumulatedDistance + esmb_Distance)
esmb_Ticks := (esmb_AccumulatedDistance // esmb_Threshold) ; floor divide
esmb_AccumulatedDistance := (esmb_AccumulatedDistance - (esmb_Ticks * esmb_Threshold))
esmb_WheelDirection := "WheelDown"
if (esmb_Ticks < 0) {
esmb_WheelDirection := "WheelUp"
esmb_Ticks := (-1 * esmb_Ticks)
}
;; Do not send clicks on the first iteration
if esmb_FirstIteration = y
esmb_FirstIteration = n
else {
Loop % esmb_Ticks {
MouseClick, %esmb_WheelDirection%
}
}
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