Run AutoHotkey scripts from your phone
KMacros works well with AutoHotkey (AHK). Each key on your phone can launch an AHK script or call one function from a large script, so you can stop memorizing hotkey combinations and press a labeled key instead.
KMacros runs AutoHotkey v1 and v2 scripts through the AutoHotkey program that is already installed on your PC. KMacros does not include AutoHotkey, and it does not change your scripts.
Why use a phone as an AutoHotkey keyboard
AutoHotkey makes it easy to write hundreds of small automations, but every automation needs a hotkey you can remember. A KMacros keyboard gives each one its own key with a label, an icon, and a color. The keys work the same way in every app, they never collide with the shortcuts of the program you are using, and you can group them on separate keyboards, for example one for writing, one for streaming, and one for window management.
Recommended: one script, one key for each function
If you keep a long list of AHK functions in one file, keep them there. Add a short dispatcher at the top that runs the function named on the command line, and give each key a Run a program step that names the function it should call.
1. Add the dispatcher to your script (AutoHotkey v2)
#Requires AutoHotkey v2.0
#SingleInstance Off
#NoTrayIcon
; Usage: keys.ahk FunctionName [arguments...]
if A_Args.Length = 0
ExitApp
fn := A_Args.RemoveAt(1)
try
%fn%(A_Args*)
catch
ExitApp 1
ExitApp
ToggleDarkMode() {
; your code
}
OpenStandupNotes() {
; your code
}
For AutoHotkey v1, replace the dispatcher with this version and keep the rest of the file the same:
#NoTrayIcon
#SingleInstance Off
fn := A_Args.RemoveAt(1)
Func(fn).Call(A_Args*)
ExitApp
2. Add a Run a program step to each key
- In the KMacros PC app, click the key, click Add step, and choose Run a program.
- For the program, browse to your AutoHotkey executable. For v2 this is usually
C:\Program Files\AutoHotkey\v2\AutoHotkey64.exe. - For the arguments, enter the script and the function name:
"C:\ahk\keys.ahk" ToggleDarkMode - Set the window to Hidden, press Test, and then use the key from your phone.
Each press starts a new AutoHotkey process, which usually takes less than a fifth of a second. Variables do not carry over from one press to the next, so keep state in a file or in the registry if a function needs it.
Pass a value from a slider or a toggle
KMacros fills in placeholders in the arguments before it starts the program. A slider key can send its value to a function, and a toggle key can say whether it was switched on or off:
| Placeholder | What it becomes |
|---|---|
{value} | The slider's value. |
{on} | 1 when a toggle key is switched on, or 0 when it is switched off. |
{state} | The state of a hold key (down or up). |
{label}, {keyboard}, {phone} | The key's label, the keyboard's name, and the phone's name. |
For example, a slider key with the arguments "C:\ahk\keys.ahk" SetBrightness {value} calls SetBrightness(value) with a number from the slider as text. Convert it with Integer(value) in v2 or value + 0 in v1.
Show whether the script worked
Set the step's report option to Finishes, and the key on your phone shows a success or failure ring when the script ends. A script that ends with ExitApp 1 (as the dispatcher above does when a function fails) counts as a failure.
Other ways to connect KMacros and AutoHotkey
Send a hotkey that your script already defines
If your script already has hotkeys, add a Keys step to the key and record the same combination. AutoHotkey sees it as ordinary keyboard input. Unusual combinations such as Ctrl+Alt+Shift+F1 are the safest, because other programs rarely use them.
Run a whole script
To run a single script that needs no function name, choose Run a program and browse to the .ahk file. Windows opens it with AutoHotkey.
Keep a script running and let it listen
For work that needs memory between presses, run one AutoHotkey script all the time and set the key's step to Notify scripts. The script receives each press through the local API, so it can keep its own state. Your script can also use the same API to draw on keys, for example to show whether a mode is on.
Let an AI assistant set up the keys
If you have a long list of functions, the MCP server can bind them to keys for you. Turn on Let scripts and assistants change what keys do in the PC app, and ask your assistant to create a key for each function in your script.
Good to know
- KMacros starts AutoHotkey with the same permissions KMacros has. Windows does not let a normal program send keys to a window that runs as administrator, so a script that controls an administrator window needs KMacros to run as administrator too.
- Some games block simulated input from every program, including AutoHotkey, and those blocks apply to KMacros keys too.
- Everything runs on your PC. Your scripts and their arguments stay there, and the phone shows only a short description of what each key does.