Show / Hide Table of Contents

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 "Ctrl+Shift+Alt+Win+K", tuple (KMod, KKey), enum KKey, enum Keys, struct KHotkey.

waitModReleased  (bool)

Also wait until hotkey modifier keys released.

Returns
bool

Returns true. On timeout returns false if timeout is negative; else exception.

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.

note

Most single-key and Shift+key hotkeys don't work when the active window has higher UAC integrity level 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(5, "Ctrl+Win+K"); //exception after 5 s
if(!keys.waitForHotkey(-5, "Left")) print.it("timeout"); //returns false after 5 s