Skip to content

Instantly share code, notes, and snippets.

@jeremyredhead
Created March 5, 2021 03:46
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 jeremyredhead/4a5ca8719ee2a6d9caf3d39401603c9c to your computer and use it in GitHub Desktop.
Save jeremyredhead/4a5ca8719ee2a6d9caf3d39401603c9c to your computer and use it in GitHub Desktop.
Simple Mouse Keys AutoHotKey script
#NoEnv
; #Warn
SetWorkingDir %A_ScriptDir%
SendMode Event ; can't set mouse speed in Input/Play modes
MouseKeysEnabled := false
HotKey, *z, Off
HotKey, *z UP, Off
HotKey, *x, Off
HotKey, *x UP, Off
; doesn't work...
; ^F10::
; MouseKeysEnabled := false
; return
^F10::
; KeyWait is needed as otherwise when enabled the loop will run,
; discover that Ctrl+F10 is still held down, and thus exit and disable again
KeyWait F10
MouseKeysEnabled := not MouseKeysEnabled
; disable normal arrow key usage
; asterisk to disable w/ ALL modifiers, e.g. Ctrl+Left, Alt+Right, etc
HotKey, *Left, disable, On
HotKey, *Right, disable, On
HotKey, *Up, disable, On
HotKey, *Down, disable, On
HotKey, *z, On
HotKey, *z UP, On
HotKey, *x, On
HotKey, *x UP, On
while (MouseKeysEnabled) {
X := 0
Y := 0
Amount := 10
Speed := 1.5 ; TODO: dynamic speed or w/e
; "P" = physical state mode;
; necessary because we disabled the arrows keys above
if GetKeyState("Left", "P")
X := -Amount
if GetKeyState("Right", "P")
X := Amount
if GetKeyState("Up", "P")
Y := -Amount
if GetKeyState("Down", "P")
Y := Amount
; if GetKeyState("z", "P")
; MouseClick, Left, ,,
; X,Y is 0,0 at the top-left corner
; Speed is 0 through 100, with 100 being _slowest_
MouseMove, X, Y, Speed, R ; "R" means relative to mouse position
; GetKeyState does not support the ^!+ etc syntax
if GetKeyState("Control") and GetKeyState("F10")
; The ^F10 hotkey is still enabled *inside* of itself...
; MouseKeysEnabled will be set to false when it is triggered again
break
}
; re-enable normal arrow key usage
HotKey, *Left, disable, Off
HotKey, *Right, disable, Off
HotKey, *Up, disable, Off
HotKey, *Down, disable, Off
HotKey, *z, Off
HotKey, *z UP, Off
HotKey, *x, Off
HotKey, *x UP, Off
return
disable:
; unlike hotkeys, labels can't on same line as a command
return
; Click "does not automatically release modifier keys",
; i.e. Ctrl, Alt, Shift pass-through (which we want)
*z::Click down left
*z UP::Click up left
*x::Click down right
*x UP::Click up right
@jeremyredhead
Copy link
Author

Simple Mouse Keys for AHK

Do you use MacroSoft LWindows and AutoHotKey?
You need to use MouseKeys but can't stand how excruciatingly slowly it moves?
Or your keyboard doesn't even have a number pad!?
Then boy do I have the thing for you!

Keyboard Shortcuts Hotkeys

Initially starts disabled, use Ctrl+F10 to enable/disable Simple MouseKeys:tm:
When enabled, the normal arrow key usage is disabled and they move the mouse instead.
Z and X are also remapped to left and right click, respectively.
In order to Ctrl+Click, press Ctrl+Z, etc etc, and so on and so forth.
You should also be able to drag/select things by holding down Z or X.

Known Bugs

You may sometimes have to press Ctrl+F10 twice to re-enable mouse keys.

TODO

  • Middle click, and mouse wheel/scrolling
  • Easily reconfigurable shortcu- hotkeys
  • Variable(?) speed/movement (i.e. it should speed up the longer you hold down)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment