PowerKeys Scripting API
    Preparing search index...

    Interface KeyboardAPI

    interface KeyboardAPI {
        Type(text: string, delayMs?: number): Promise<void>;
        Press(keyCombo: string, settleMs?: number): Promise<void>;
        Hold(key: string): Promise<void>;
        Release(key: string): Promise<void>;
        Sequence(): KeySequence;
        OnRawEvent(callback: EventCallback<[event: KeyEvent]>): void;
        SendTo(windowId: string, keyCombo: string): Promise<void>;
        PostMessage(
            windowId: string,
            message: number,
            wParam: number,
            lParam: number,
        ): void;
        PostKey(windowId: string, keyCombo: string): void;
    }
    Index
    • Types text character-by-character by simulating individual key presses.

      Parameters

      • text: string

        The string to type.

      • OptionaldelayMs: number

        Non-negative minimum delay after every character, including the final character. Defaults to 0; scheduling can make waits longer.

      Returns Promise<void>

      Resolves after all characters have been injected and their requested delays have elapsed.

      await Keyboard.Type("Hello, world!", 50); // 50ms delay between keys
      

      keyboard

    • Sends a key combination (press then release).

      Combo format: modifier keys joined with + followed by the main key. Either-side modifiers: Ctrl, Shift, Alt, Win. Lateral modifiers: LCtrl, RCtrl, LShift, RShift, LAlt, RAlt, LWin, RWin.

      Parameters

      • keyCombo: string

        Key combination string, e.g. "Ctrl+Shift+T", "Alt+F4", "Enter".

      • OptionalsettleMs: number

        Non-negative minimum delay applied after modifier key-downs before the main key and again after the main key before modifier release. No delay is applied when the combo has no modifiers. Defaults to 5; scheduling can make waits longer.

      Returns Promise<void>

      Resolves after the key press and modifier settle intervals complete.

      USE CASE: Foreground input, the currently active window receives the keystrokes. For sending keys to a background window without focusing it, use PostKey instead.

      await Keyboard.Press("Ctrl+Shift+T"); // reopen closed tab
      await Keyboard.Press("Alt+F4");

      keyboard

    • Presses and holds a key or key combination without releasing it. Use Keyboard.Release() to let go.

      Parameters

      • key: string

        Key combination string, e.g. "Shift", "Ctrl+A".

      Returns Promise<void>

      Resolves after the key-down events are injected.

      await Keyboard.Hold("Shift");
      await Keyboard.Type("hello"); // types HELLO
      await Keyboard.Release("Shift");

      keyboard

    • Releases a previously held key or key combination.

      Parameters

      • key: string

        Key combination string that was passed to Keyboard.Hold().

      Returns Promise<void>

      Resolves after the key-up events are injected.

      await Keyboard.Release("Shift");
      

      keyboard

    • Creates a KeySequence builder for batching multiple keyboard operations. All steps execute sequentially while holding the script's input lane, so other input operations cannot interleave between them. Call .Send() to execute the batch.

      Returns KeySequence

      A new empty chainable sequence builder; call Send to execute its accumulated steps.

      USE CASE: Tight key sequences requiring precise inter-key timing with no separately scheduled input operations between steps. Preferred over multiple sequential Hold/Press/Release calls when timing predictability matters.

      await Keyboard.Sequence()
      .Hold("Ctrl")
      .Press("C")
      .Release("Ctrl")
      .Send();

      keyboard

    • Registers a callback that fires on every raw keyboard event (key down and key up). The script enters an event loop and stays alive as long as this handler is registered.

      Parameters

      Returns void

      USE CASE: Per-device filtering (use event.device_id to isolate a specific keyboard), or inspecting raw virtual-key codes before hotkey matching occurs.

      Keyboard.OnRawEvent((e) => {
      if (e.type === "down" && e.virtual_key === 0x41) {
      Console.Log("A pressed");
      }
      });

      keyboard

    • Focuses a window and sends a key combination to it. This is a convenience wrapper that calls Window.Focus() followed by Keyboard.Press().

      Parameters

      • windowId: string

        Window identifier from WindowInfo.id.

      • keyCombo: string

        Key combination string, e.g. "Ctrl+C", "Enter".

      Returns Promise<void>

      Resolves after the window is focused and the key press completes.

      USE CASE: Sending input to a specific app while keeping it in the foreground. The window is focused before the key is sent. For background delivery without stealing focus, use PostKey instead.

      const [win] = Window.Find({ process: "notepad.exe" });
      await Keyboard.SendTo(win.id, "Ctrl+A"); // select all in Notepad

      keyboard

      window

    • Posts a window message to a specific window using PostMessageW. Use for low-level message injection (e.g. WM_KEYDOWN, WM_CHAR).

      Parameters

      • windowId: string

        Window identifier from WindowInfo.id.

      • message: number

        Windows message identifier (for example 0x0100 for WM_KEYDOWN).

      • wParam: number

        Message-specific non-negative wParam bit pattern within JavaScript's safe-integer range.

      • lParam: number

        Message-specific signed lParam bit pattern within JavaScript's safe-integer range.

      Returns void

      USE CASE: Background automation, the target window does not need to be focused. LIMITATION: Unreliable for competitive games using Raw Input and DirectInput applications; use Keyboard.Press for those instead. Works well for standard Win32 and WPF applications.

      const [win] = Window.Find({ process: "notepad.exe" });
      // Send WM_KEYDOWN for the 'A' key (VK_A = 0x41)
      Keyboard.PostMessage(win.id, 0x0100, 0x41, 0);
      Keyboard.PostMessage(win.id, 0x0101, 0x41, 0); // WM_KEYUP

      keyboard

    • Posts WM_KEYDOWN and WM_KEYUP messages for a key combination to a specific window. Convenience wrapper around PostMessage that constructs proper keyboard messages including modifier keys and scan codes.

      Parameters

      • windowId: string

        Window identifier from WindowInfo.id.

      • keyCombo: string

        Key combination string, e.g. "Ctrl+V", "A".

      Returns void

      USE CASE: Background key injection without focusing the window. Handles modifier key press/release ordering automatically. LIMITATION: Unreliable for games and DirectInput applications.

      const [win] = Window.Find({ process: "notepad.exe" });
      Keyboard.PostKey(win.id, "Ctrl+V"); // paste in background

      keyboard