A lightweight Lua script for Logitech GHub that ensures only one macro runs at a time, with per-key toggle/hold modes and adds abort keys. Works seamlessly across mouse and keyboard G-keys.
- 🖱️ Mouse G-buttons & ⌨️ Keyboard G-keys
- 🔁 Per-key modes
toggle: press to start/stop; switches if another macro is runninghold: starts on press, stops on release (only if the same key started it)
- 🛑 Abort keys per device
- 🧠 Debounce for press events to prevent double-triggers
- 🔊 Optional debug logging
- 🧪 Debug toggle to discover key numbers and trace behavior
- Open Logitech GHub (or LGS) and select your device profile.
- Go to Scripting → create a new Lua script.
- Paste the contents of
src/ghub_macro_controller.lua. - Edit the CONFIG section near the top:
- Map your desired keys under
macros.mouseand/ormacros.keyboard. - Optionally set
abort_keys.mouse/abort_keys.keyboard. - Adjust
debounce_msif needed. - Optional: turn on debug logging (see below).
- Map your desired keys under
-- Mouse examples:
-- [4] = { name = "MyMouseMacroA", mode = "toggle" },
-- [5] = { name = "MyMouseMacroB", mode = "hold" },
-- Keyboard examples:
-- [1] = { name = "MyKeyboardMacroA", mode = "toggle" },
-- [2] = { name = "MyKeyboardMacroB", mode = "hold" },
-- Abort keys (stop all macros):
-- abort_keys.mouse = { 6 }
-- abort_keys.keyboard = { 12 }
-- Debug toggles:
-- debug = {
-- log_events = true, -- prints each raw OnEvent (helps discover key numbers)
-- log_unmapped = true, -- logs presses/releases for unmapped keys
-- log_macros = true, -- logs start/stop/switch decisions
-- }💡 Tip: If you use just a string (e.g.,
[4] = "MyMacro"), it defaults tomode = "toggle".
- Pressing a mapped key:
- If nothing is running → starts that macro.
- If the same macro is running → stops it (toggle off).
- If a different macro is running → switches cleanly.
- Hold mode:
- Starts on press and stops when that same key is released.
- Releasing another key won’t stop it (ownership tracked).
- Abort keys:
- Stop any running macro immediately and clear ownership.
- Debounce:
- Filters duplicate
PRESSevents for the same key within a short window (default 120 ms).
- Filters duplicate
- Debug logging:
log_eventsprintsEvent=... Arg=...for every GHUB/LGS event. Use this to discover key numbers.log_unmappedprints when you press/release a key that isn’t configured.log_macrosprints internal decisions (play/stop/switch).
- I don’t know my key numbers (arg values):
SetCONFIG.debug.log_events = true, then press your G-keys/buttons. Watch the log for lines likeEvent=MOUSE_BUTTON_PRESSED Arg=4orEvent=G_PRESSED Arg=1. Use those numbers in yourmacros/abort_keysmappings. Turn it off afterward. - Nothing happens on press: ensure the key is defined in
CONFIG.macrosand that the macro name matches the one you created in GHub/LGS. - Hold macro stops on the wrong release: check for duplicate key IDs; ownership is per key.
- Double start/stop in logs: increase
debounce_ms(150–180 ms) or set it to0to disable. - Abort doesn’t work: verify abort key numbers match your device’s
argvalues. Debug logs help here.
MIT © 2025 PeluxGit