I'm working on a script that focuses on faster mousing. It has hotkeys to:snap the cursor to hard-coded locations,swap the cursor to the location where it was last swapped from, andsave and snap to custom locations.I've been steadily refactoring with an eye to DRY and other principles. For example, the script used to manually define several variables, but now it uses an array. However, I'm coming from a Python background and still getting used to AHK, so the mix between traditional variables vs expressions, commands vs functions, etc. is kind of confusing.MoveLocation used to also send a click if the cursor was within 10 pixels of that saved location, but I ran into some problems:The click was being sent while the hotkey modifiers were held down. I bypassed this by checking whether the key was physically held down... sometimes (I'm calling these hotkeys with extra mouse buttons mapped to the various defined hotkeys), which mostly worked, but it would still include Control while clicking File Explorer in the taskbar with multiple windows open. Thus, instead of popping the row of window previews, it would swap between each window, which is what happens if you Control-click that. To avoid this, I used...The Sleep command, which, while solving the problem, also introduced a noticeable delay. It only handled Control reliably with a delay of 50ms or more, which was bugging me.Here's the removed code:; if Ctrl isn't physically held down, stop sending itif GetKeyState(Ctrl, P) {    Send {Ctrl Up}    Sleep, 50}MouseGetPos, tempx, tempy; if the current position is close to the save point, click itif (Abs(tempx-x)<10 && Abs(tempy-y)<10) {    MouseMove, x, y    Click} ; is clicking a good idea? might be cleaner to remove that logic; otherwise, move to the save pointelse {Removing that made the script more reliable and consistent. It's not much of a hassle to just use the ordinary mouse button to click saved hotspots. However, I now feel that maybe there's some other useful thing I could have the script do if I click the go to hotspot hotkey while the cursor is already on it.The current version of the script that I'm actively practicing with is shown below:#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.; #Warn  ; Enable warnings to assist with detecting common errors.SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.CoordMode, Mouse, ScreenSetDefaultMouseSpeed, 0SysGet, TotalWidth, 78SysGet, TotalHeight, 79SysGet, monitors, MonitorCountoffset := TotalWidth // monitorsstart := offset // 2x1 := start + offset * 0x2 := start + offset * 1y := TotalHeight // 2rx1 := x1ry1 := yrx2 := x2ry1 := ycount := 0locations := []Loop 11 {    locations.Push([0,0])}; shift-pause to snap to left monitor, alt-pause to right+Pause::MouseMove, x1, y!Pause::MouseMove, x2, y; swap to last swapped locationPause::    if (count) {        MouseGetPos, rx1, ry1        MouseMove, rx2, ry2        count--    }    else {        MouseGetPos, rx2, ry2        MouseMove, rx1, ry1        count++    }    return; Ctrl+Shift+NumpadNumber to save a hotspot; Ctrl+NumpadNumber to go to or click a hotspotMoveLocation(ID) {    global locations    MouseMove, locations[ID][1], locations[ID][2]}SaveLocation(ID) {    MouseGetPos, x, y    global locations    locations[ID] := [x, y]}^NumpadEnd::SaveLocation(1)^Numpad1::MoveLocation(1)^NumpadDown::SaveLocation(2)^Numpad2::MoveLocation(2)^NumpadPgDn::SaveLocation(3)^Numpad3::MoveLocation(3)^NumpadLeft::SaveLocation(4)^Numpad4::MoveLocation(4)^NumpadClear::SaveLocation(5)^Numpad5::MoveLocation(5)^NumpadRight::SaveLocation(6)^Numpad6::MoveLocation(6)^NumpadHome::SaveLocation(7)^Numpad7::MoveLocation(7)^NumpadUp::SaveLocation(8)^Numpad8::MoveLocation(8)^NumpadPgUp::SaveLocation(9)^Numpad9::MoveLocation(9)^NumpadIns::SaveLocation(10)^Numpad0::MoveLocation(10)^NumpadDel::SaveLocation(11)^NumpadDot::MoveLocation(11); mousewheel version for basic mice~MButton & WheelUp::    Send {Esc}    MouseMove, x1, y    return~MButton & WheelDown::    Send {Esc}    MouseMove, x2, y    returnThere's still some code smell from that big block of SaveLocation/MoveLocation hotkey definitions near the bottom. Unfortunately, I couldn't figure out the Hotkey command, and using Shift as a modifier with the number pad requires different key names (e.g. ^NumpadEnd instead of ^+Numpad1), so I don't even know if Hotkey would work.I welcome answers related to refactoring or to the actual utility of the script.
Mouse movement function
autohotkey