AutoHotkey
Included with Macro DeckKeep your AutoHotkey v2 scripts in Macro Deck, run and stop them from a button and let them read and set variables.
The Scripts tab of the AutoHotkey integration with a list of scripts and one open in the editor
- Write, check and test AutoHotkey v2 scripts in Macro Deck
- Run scripts, .ahk files or inline code from a button
- Start, stop and toggle scripts that keep running
- Pass values safely as parameters
- Scripts can read and set variables and show notifications
The AutoHotkey integration runs AutoHotkey v2 scripts from your buttons and automations: sending keys to a window in the background, arranging windows, app-specific hotkeys and anything else AutoHotkey can do. It is available on Windows only and is off until you turn it on. Macro Deck does not include AutoHotkey; it finds the AutoHotkey v2 you installed, or a portable one you choose. AutoHotkey v1 is not supported.
What you can do
- Keep your scripts on the integration's Scripts tab, edit them with syntax highlighting, Check syntax and run them right there. Last run shows how the latest run went, its result, errors with their line, and the script's output.
- Run a script from the library with Run AutoHotkey script, an
.ahkfile where it is stored with Run AutoHotkey file, or code written in the action itself with Run inline AutoHotkey code. - Start scripts with hotkeys or timers together with Macro Deck, and start and stop them with Toggle AutoHotkey script. The button shows Running or Not running.
- Pass values to a script as Parameters. Macro Deck never inserts values into the text of a script, so a value cannot break or change your code. The script reads them as
MacroDeck.Params["name"]. - Let a script talk back through the Macro Deck helper:
MacroDeck.GetVarandMacroDeck.SetVarread and set variables,MacroDeck.Notifyshows a notification andMacroDeck.SetResultreports a result to the action. - Start an automation when a script starts, exits or fails.
Some example setups:
- A Toggle AutoHotkey script button for a script with your gaming hotkeys, with its own look for Running and Not running.
- A button that runs a script with the parameter
volumeset to{{ vars.volume }}, and the script callsSoundSetVolume MacroDeck.Params["volume"]. - An automation on AutoHotkey script failed that shows
{{ event.reason }}on a button.
How scripts run
AutoHotkey never shows its error dialogs for scripts Macro Deck runs: load errors and runtime errors appear under Last run and make an action that waits fail. A script that is stopped is asked to close first, so its OnExit routine runs, and is ended after the Stop grace period in seconds. Stop and Toggle only touch scripts Macro Deck started. When Macro Deck exits or you turn the integration off, it stops all the AutoHotkey scripts it started.
When you migrate from Macro Deck 2, buttons of the AutoHotkey plugin by jbcarreon123 that run AutoHotkey v2 scripts move over to these actions.
What you need
- Windows.
- AutoHotkey v2, installed or portable. Macro Deck does not include it.
Set it up
Step 1: Install AutoHotkey v2
Download AutoHotkey v2 from autohotkey.com and install it. Macro Deck finds it where the installer put it.
Step 2: Turn on the integration
In Macro Deck, click Integrations in the sidebar, click AutoHotkey and turn on the switch at the top right. When Macro Deck cannot find AutoHotkey v2, the page shows AutoHotkey not found: install it and click Check again.
Step 3: Check the AutoHotkey settings
On the Overview tab, click Set up in the Configuration section. AutoHotkey settings shows the AutoHotkey in use and its version. For a portable AutoHotkey, set AutoHotkey executable to Choose the executable and pick its
AutoHotkey64.exeas Executable. Click Continue.Step 4: Write a script
Open the Scripts tab and click + next to the list title. Enter a name, click Create script, then write the script in the editor, for example
MsgBox "Hello from Macro Deck". Click Save, then Run to try it.Step 5: Add an action to a button
On the Deck page, click the button you want to use. The deck must be unlocked: when the button at the top right reads Lock, it is unlocked. The editor opens with Short Press selected. Click + Add action, select AutoHotkey on the left of the Add action dialog and pick Run AutoHotkey script. Choose your script as AutoHotkey script, then click Save.
Step 6: Press the button
Press the button on your deck. The script runs, and Last run on the Scripts tab shows how it went.
Actions7
Put these on a button or run them from a flow.
- Run AutoHotkey script
- Runs a script from the Scripts tab with parameters, and can wait until it finishes.
- Run AutoHotkey file
- Runs an
.ahkfile where it is stored on your computer, with arguments inA_Argsand parameters. - Run inline AutoHotkey code
- Runs AutoHotkey v2 code written in the action itself.
- Stop AutoHotkey script
- Stops a script or file Macro Deck started: all instances, or only the most recent one.
- Restart AutoHotkey script
- Stops a script or file and starts it again with new parameters, or starts it when it is not running.
- Toggle AutoHotkey script
- Starts a script or file when Macro Deck does not run it and stops it when it does. Shows Running or Not running on the button.
- Open Window Spy
- Opens the Window Spy of AutoHotkey to look up window titles, classes and controls.
Triggers3
A button or flow can react to these events.
- AutoHotkey script started
- A script Macro Deck started has loaded and runs.
- AutoHotkey script exited
- Such a script has ended, with its exit code and how long it ran.
- AutoHotkey script failed
- A script could not be started or loaded, reported an error, or did not finish in time.
Variables4
Show these values on buttons and widgets, or use them in conditions.
autohotkey_installed,autohotkey_version- Whether Macro Deck found a working AutoHotkey v2, and its version.
autohotkey_running_scripts- How many AutoHotkey scripts Macro Deck runs right now.
autohotkey_last_script,autohotkey_last_exit_code,autohotkey_last_result,autohotkey_last_error- The script that ended or failed last, its exit code, the result it reported with
MacroDeck.SetResultand why it failed, when it did. autohotkey_script_<name>_running- Whether a script from the library runs, one for each script. The name stays the same when you rename the script.
Frequently asked questions
Does it work with AutoHotkey v1 scripts?
No. Macro Deck supports AutoHotkey v2 only, and code written for AutoHotkey v1 does not load in v2. Check syntax on the Scripts tab shows the line of the first error.
How do I get a value from Macro Deck into my script?
Add it as a parameter in the action, for example volume with the value {{ vars.volume }}, and read it in the script as MacroDeck.Params["volume"]. Values always arrive as text, exactly as entered. A script can also read a variable at any time with MacroDeck.GetVar("name").
Why does my script not send keys to a game or tool?
Macro Deck runs scripts without administrator rights, and Windows does not let them send keys or clicks to a window of a program that runs as administrator.
What happens to my scripts when Macro Deck closes?
Macro Deck stops every AutoHotkey script it started when it exits or when you turn the integration off. Turn on Start when Macro Deck starts in the Settings of a script to have it running whenever Macro Deck runs. Programs a script opened stay open.
Can I keep using my .ahk files?
Yes. Run AutoHotkey file runs a file where it is stored, so A_ScriptDir is its folder. You can also import a file into the library on the Scripts tab.
More in Your computer
System
Included with Macro DeckControl your computer from your deck: apps, volume, commands, notifications, sleep and shutdown.
Keyboard
Included with Macro DeckPress shortcuts, type text and run key sequences on your computer from a button.
Mouse
Included with Macro DeckClick, move the pointer, drag and scroll on your computer from a button.
ADB / Android Debug Bridge
Included with Macro DeckControl an Android phone or tablet over USB or Wi-Fi: wake it, start apps, tap, type and take screenshots.
Steam
Included with Macro DeckStart and close Steam games, and show what you play, your friends and your library on your deck.