Some AutoHotKey tips: 1. Don't shirk on good practice. Most AHK code in the wild is jank because most AHK coders aren't software developers, they don't know any better. But you do, so use functions, proper data structures, abstractions, etc and the process will be a lot nicer.
May 23, 2022 · 4:14 AM UTC
3 1 34
2. You can use window groups to restrict a hotkey to just web browsers (via IfWinActive) or make a hotkey that alt-tabs through a specific set of programs (via GroupActivate) autohotkey.com/docs/commands…
1 4
3. The #If directive takes expressions. I have Numpad- flip a `subscript_mode` flag and two sets of hotkeys that are conditionally activate. That way I can use the same keycombo for ¹ and ₁ autohotkey.com/docs/commands…
1 1
4. Find ways to group similar operations under the same root hotkeys. My favorite trick is using Input to make hotkeys that are two keypresses *in sequence*. So `^+d` could be the "open file" root, and the letter you press next determines *which* file autohotkey.com/docs/commands…
1 1
5. If you're doing the Input trick and storing options in an object map, be aware that dicts are case insensitive and you'll have problems if both `a` and `A` are in the dict. I built a weird workaround, you should probably just use a COM object docs.microsoft.com/en-us/off…
1 1
6. Also you can't index on strings, you have to use SubStr, but AHK will silently fail without giving an error if you try to index, which is hair-pullingly hard to figure out
1 1
7. `^d` is the hotkey "ctrl+d". `>^d` is the same, but ONLY when right ctrl is pressed. I use this to only place hotkeys on the right modifiers so I can use the left modifiers for the system default hotkeys autohotkey.com/docs/Hotkeys.…
1 2
9. AHK is godawful at lots of things like database access, datetime processing, and string munging. If you have to do that, you're better off using RunWait to call an auxiliary program and doing the calculations there autohotkey.com/docs/commands…
2
Here's a godawful example of shelling to python timeshim := A_WorkingDir . "\Lib\Aux-Scripts\timeshim.py" cliptime := clipboard cmd := "pythonw.exe " . timeshim . " --date=""" . cliptime . """ | clip" RunWait, %ComSpec% /c "%cmd%",,Hide out := clipboard return out
1 1
11. Most remote presentation clickers work by sending keyboard codes to the computer, you can use AHK to make them into remote controls for any app. I once had my clicker restart songs in Spotify to practice a dance thing
1 1
12. Most programs don't let you remap keyboard shortcuts to mouse buttons like ctrl+middleclick or MouseWheelLeft, but you can add mouse shortcuts in AHK! eg #IfWinActive, ahk_exe audacity.exe MButton::Send ^l
1 1
13. AHK comes with a bunch of special variables, like A_ScriptDir for the file directory the running script is located in autohotkey.com/docs/Variable…
1
14. My favorite hotstring sigil is `;`, because there's basically never a situation where an alphanumeric character follows a ; in English or software. 15. Gleefully abuse the "hotstring helper" at the bottom of this link, it's great autohotkey.com/docs/Hotstrin…
3 4