Created
December 10, 2023 21:01
-
-
Save sirkkalap/2799c3bbebb50c256f0947585d4729c3 to your computer and use it in GitHub Desktop.
AutoHotkey script to type WASD keys using relative mouse movements when RShift is pressed.
This file contains hidden or 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
#Persistent | |
SetTimer, CheckMouse, 10 | |
return | |
; Initialize state variables | |
WDown := false | |
ADown := false | |
SDown := false | |
DDown := false | |
CheckMouse: | |
; Save the previous mouse x- and y-coordinates | |
PrevMouseX := MouseX | |
PrevMouseY := MouseY | |
MouseGetPos, mouseX, mouseY | |
; Set the sensitivity for movement (adjust as needed) | |
Sensitivity := 5 | |
; Check if the XButton5 (mouse button 5) is pressed | |
if (GetKeyState("RShift", "P")) | |
{ | |
; Calculate delta x and delta y | |
DeltaX := mouseX - PrevMouseX | |
DeltaY := mouseY - PrevMouseY | |
; Simulate WASD key presses based on delta x and delta y | |
if (DeltaX > Sensitivity) | |
{ | |
if (!DDown) | |
{ | |
SendInput, {D down} | |
DDown := true | |
} | |
} | |
else if (DDown) | |
{ | |
SendInput, {D up} | |
DDown := false | |
} | |
if (DeltaX < -Sensitivity) | |
{ | |
if (!ADown) | |
{ | |
SendInput, {A down} | |
ADown := true | |
} | |
} | |
else if (ADown) | |
{ | |
SendInput, {A up} | |
ADown := false | |
} | |
if (DeltaY > Sensitivity) | |
{ | |
if (!SDown) | |
{ | |
SendInput, {S down} | |
SDown := true | |
} | |
} | |
else if (SDown) | |
{ | |
SendInput, {S up} | |
SDown := false | |
} | |
if (DeltaY < -Sensitivity) | |
{ | |
if (!WDown) | |
{ | |
SendInput, {W down} | |
WDown := true | |
} | |
} | |
else if (WDown) | |
{ | |
SendInput, {W up} | |
WDown := false | |
} | |
} | |
else | |
{ | |
; If XButton5 is not pressed, ensure that WASD key presses are released only if any of them was pressed | |
if (WDown) | |
SendInput, {W up} | |
if (ADown) | |
SendInput, {A up} | |
if (SDown) | |
SendInput, {S up} | |
if (DDown) | |
SendInput, {D up} | |
; Reset state variables | |
WDown := false | |
ADown := false | |
SDown := false | |
DDown := false | |
} | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment