hammerspoon2-docs
    Preparing search index...

    Function keyStroke

    • Send a key down and key up event with optional modifier keys, optionally to a specific application.

      A 5 ms pause is inserted between the key-down and key-up events to improve compatibility with applications that miss very fast synthetic keystrokes.

      Without app, the keystroke is posted to the system, so it goes to whichever application is frontmost. With app, it is delivered straight to that application, even if it's in the background, without activating it. In that case the modifier keys are also pressed and released around the key, as a real keyboard does, so applications that track modifier key presses themselves see them held.

      Parameters

      • mods: string[]

        An array of modifier names (e.g. ["cmd", "shift"])

      • key: string | number

        A key name or character (e.g. "a", "space", "return"), resolved

      • Optionalapp: HSApplication | null

        The application to send the keystroke to. Omit, or pass null, to

      Returns void