Created
January 16, 2023 23:57
-
-
Save mpalpha/358b9537423efb87e4a4cd327cad0316 to your computer and use it in GitHub Desktop.
auto hotkey script to mirror mouse clicks to joystick buttons 1, 2, and 3 (configurable)
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
; Change these values to use joystick button numbers other than 1, 2, and 3 for | |
; the left, right, and middle mouse buttons. Available numbers are 1 through 32. | |
; Use the Joystick Test Script to find out your joystick's numbers more easily. | |
ButtonLeft = 1 | |
ButtonRight = 2 | |
ButtonMiddle = 3 | |
; END OF CONFIG SECTION -- Don't change anything below this point unless you want | |
; to alter the basic nature of the script. | |
#SingleInstance | |
JoystickPrefix = %JoystickNumber%Joy | |
Hotkey, %JoystickPrefix%%ButtonLeft%, ButtonLeft | |
Hotkey, %JoystickPrefix%%ButtonRight%, ButtonRight | |
Hotkey, %JoystickPrefix%%ButtonMiddle%, ButtonMiddle | |
return ; End of auto-execute section. | |
; The subroutines below do not use KeyWait because that would sometimes trap the | |
; WatchJoystick quasi-thread beneath the wait-for-button-up thread, which would | |
; effectively prevent mouse-dragging with the joystick. | |
ButtonLeft: | |
SetMouseDelay, -1 ; Makes movement smoother. | |
MouseClick, left,,, 1, 0, D ; Hold down the left mouse button. | |
SetTimer, WaitForLeftButtonUp, 10 | |
return | |
ButtonRight: | |
SetMouseDelay, -1 ; Makes movement smoother. | |
MouseClick, right,,, 1, 0, D ; Hold down the right mouse button. | |
SetTimer, WaitForRightButtonUp, 10 | |
return | |
ButtonMiddle: | |
SetMouseDelay, -1 ; Makes movement smoother. | |
MouseClick, middle,,, 1, 0, D ; Hold down the right mouse button. | |
SetTimer, WaitForMiddleButtonUp, 10 | |
return | |
WaitForLeftButtonUp: | |
if GetKeyState(JoystickPrefix . ButtonLeft) | |
return ; The button is still, down, so keep waiting. | |
; Otherwise, the button has been released. | |
SetTimer, WaitForLeftButtonUp, Off | |
SetMouseDelay, -1 ; Makes movement smoother. | |
MouseClick, left,,, 1, 0, U ; Release the mouse button. | |
return | |
WaitForRightButtonUp: | |
if GetKeyState(JoystickPrefix . ButtonRight) | |
return ; The button is still, down, so keep waiting. | |
; Otherwise, the button has been released. | |
SetTimer, WaitForRightButtonUp, Off | |
MouseClick, right,,, 1, 0, U ; Release the mouse button. | |
return | |
WaitForMiddleButtonUp: | |
if GetKeyState(JoystickPrefix . ButtonMiddle) | |
return ; The button is still, down, so keep waiting. | |
; Otherwise, the button has been released. | |
SetTimer, WaitForMiddleButtonUp, Off | |
MouseClick, middle,,, 1, 0, U ; Release the mouse button. | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment