Method keys.waitForHotkey
Overload
Registers a temporary hotkey and waits for it.
public static bool waitForHotkey(Seconds timeout, KHotkey hotkey, bool waitModReleased = false)
Parameters
timeout (Seconds)
Timeout, seconds. Can be 0 (infinite), >0 (exception) or <0 (no exception). More info: Wait timeout. |
hotkey (KHotkey)
Hotkey. Can be: string like |
waitModReleased (bool)
Also wait until hotkey modifier keys released. |
Returns
bool
Returns |
Exceptions
ArgumentException
Error in hotkey string. |
AuException
Failed to register hotkey. |
TimeoutException
timeout time has expired (if > 0). |
Remarks
Uses RegisteredHotkey (API RegisterHotKey).
Fails if the hotkey is currently registered by this or another application or used by Windows. Also if F12
.
note
Most single-key and Shift+key
hotkeys don't work when the active window has higher UAC integrity level (eg admin) than this process. Media keys may work.
Examples
keys.waitForHotkey(0, "F11");
keys.waitForHotkey(0, KKey.F11);
keys.waitForHotkey(0, "Shift+A", true);
keys.waitForHotkey(0, (KMod.Ctrl | KMod.Shift, KKey.P)); //Ctrl+Shift+P
keys.waitForHotkey(0, Keys.Control | Keys.Alt | Keys.H); //Ctrl+Alt+H
keys.waitForHotkey(5, "Ctrl+Win+K"); //exception after 5 s
if(!keys.waitForHotkey(-5, "Left")) print.it("timeout"); //returns false after 5 s