interface KeyboardAPI {
    Type(text: string, delayMs?: number): void;
    Press(keyCombo: string, settleMs?: number): void;
    Hold(key: string): void;
    Release(key: string): void;
    Sequence(): KeySequence;
    OnRawEvent(callback: (event: KeyEvent) => void): void;
    SendTo(windowId: string, keyCombo: string): void;
    PostMessage(
        windowId: string,
        message: number,
        wParam: number,
        lParam: number,
    ): void;
    PostKey(windowId: string, keyCombo: string): void;
}

Methods

  • Types text character-by-character by simulating individual key presses.

    Parameters

    • text: string

      The string to type.

    • OptionaldelayMs: number

      Delay in milliseconds between each keystroke. Defaults to 0.

    Returns void

    Keyboard.Type("Hello, world!", 50); // 50ms delay between keys
    
  • 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

      Delay in milliseconds between modifier press and key press. Defaults to 5.

    Returns void

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

    Keyboard.Press("Ctrl+Shift+T"); // reopen closed tab
    Keyboard.Press("Alt+F4");
  • 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 void

    Keyboard.Hold("Shift");
    Keyboard.Type("hello"); // types HELLO
    Keyboard.Release("Shift");
  • Releases a previously held key or key combination.

    Parameters

    • key: string

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

    Returns void

    Keyboard.Release("Shift");
    
  • Creates a KeySequence builder for batching multiple keyboard operations. All steps execute sequentially on a single native thread with no JS event-loop overhead between them. Call .Send() to execute the batch.

    Returns KeySequence

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

    Keyboard.Sequence()
    .Hold("Ctrl")
    .Press("C")
    .Release("Ctrl")
    .Send();
  • 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

    • callback: (event: KeyEvent) => void

      Handler receiving a KeyEvent for each keyboard event.

    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");
    }
    });
  • 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 void

    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" });
    Keyboard.SendTo(win.id, "Ctrl+A"); // select all in Notepad
  • 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 constant (e.g. 0x0100 for WM_KEYDOWN).

    • wParam: number

      wParam value for the message.

    • lParam: number

      lParam value for the message.

    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
  • 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