KeyboardClass class provides methods to emulate keyboard input

Hierarchy

Constructors

Properties

Methods

Constructors

Properties

config: KeyboardConfig = ...

Config object for KeyboardClass class

Methods

  • pressKey presses a single Key or Key combinations Modifier Keys are to be given in "natural" ordering, so first modifier Keys, followed by the Key to press ATTENTION: There's a difference how regular keys are handled vs. modifier keys. Modifier keys will be held until released via releaseKey is called. This means that a modifier key is applied to all subsequent regular key inputs until it is released. Regular keys, on the other hand, are not held until released, so there's no automatic key repeat. If you want to have something like key repeat, please use setInterval instead.

    Parameters

    • Rest ...keys: Key[]

      Array of Keys to press and hold

    Returns Promise<KeyboardClass>

    Example

       // Will press and hold key combination CTRL + V
    await keyboard.pressKey(Key.LeftControl, Key.V);

    // This will press and hold the Shift key, so the Shift modifier is applied to each subsequent key input
    await keyboard.pressKey(Key.LeftShift);
    await keyboard.pressKey(Key.H);
    await keyboard.pressKey(Key.E);
    await keyboard.pressKey(Key.L);
    await keyboard.pressKey(Key.L);
    await keyboard.pressKey(Key.O);
    await keyboard.releaseKey(Key.LeftShift);
  • pressKey releases a single Key or Key combinations Modifier Keys are to be given in "natural" ordering, so first modifier Keys, followed by the Key to release ATTENTION: There's a difference how regular keys are handled vs. modifier keys. Modifier keys will be held until released via releaseKey is called. This means that, in contrast to regular keys, a modifier key has to be explicitly released

    Parameters

    • Rest ...keys: Key[]

      Array of Keys to release

    Returns Promise<KeyboardClass>

    Example

       // Will press and hold key combination CTRL + V
    await keyboard.pressKey(Key.LeftControl, Key.V);

    // To release the key combination CTRL + V, it's actually sufficient to call releaseKey on the modifier key
    await keyboard.releaseKey(Key.LeftControl);
  • type types a sequence of String or single Keys via system keyboard

    Parameters

    • Rest ...input: StringOrKey

      Sequence of String or Key to type

    Returns Promise<KeyboardClass>

    Example

       await keyboard.type(Key.A, Key.S, Key.D, Key.F);
    await keyboard.type("Hello, world!");

Generated using TypeDoc