A set of helpers and management functions for dealing with user input from keyboard events. https://keycode.info/

Properties

downKeys: Set<string> = ...

The set of key codes which are currently depressed (down)

moveKeys: Set<string> = ...

The set of movement keys which were recently pressed

MODIFIER_KEYS: {
    CONTROL: string;
    SHIFT: string;
    ALT: string;
} = ...

Allowed modifier keys

Type declaration

  • CONTROL: string
  • SHIFT: string
  • ALT: string
MODIFIER_CODES: {} = ...

Track which KeyboardEvent#code presses associate with each modifier

Type declaration

    PROTECTED_KEYS: string[] = ...

    Key codes which are "protected" and should not be used because they are reserved for browser-level actions.

    CONTROL_KEY_STRING: string = ...

    The OS-specific string display for what their Command key is

    KEYCODE_DISPLAY_MAPPING: Record<string, string> = ...

    A special mapping of how special KeyboardEvent#code values should map to displayed strings or symbols. Values in this configuration object override any other display formatting rules which may be applied.

    Accessors

    • get hasFocus(): boolean
    • Test whether an HTMLElement currently has focus. If so we normally don't want to process keybinding actions.

      Returns boolean

    Methods

    • Internal

      Begin listening to keyboard events.

      Returns void

    • Report whether a modifier in KeyboardManager.MODIFIER_KEYS is currently actively depressed.

      Parameters

      • modifier: string

        A modifier in MODIFIER_KEYS

      Returns boolean

      Is this modifier key currently down (active)?

    • Report whether a core action key is currently actively depressed.

      Parameters

      • action: string

        The core action to verify (ex: "target")

      Returns boolean

      Is this core action key currently down (active)?

    • Emulate a key-up event for any currently down keys. When emulating, we go backwards such that combinations such as "CONTROL + S" emulate the "S" first in order to capture modifiers.

      Parameters

      • Optional options: {
            force: boolean;
        } = {}

        Options to configure behavior.

        • force: boolean

          Force the keyup events to be handled.

      Returns void

    • Input events do not fire with isComposing = false at the end of a composition event in Chrome See: https://github.com/w3c/uievents/issues/202

      Parameters

      • event: CompositionEvent

      Returns void

    • Protected

      Processes a keyboard event context, checking it against registered keybinding actions

      Parameters

      • context: KeyboardEventContext

        The keyboard event context

      • Optional options: {
            force: boolean;
        } = {}

        Additional options to configure behavior.

        • force: boolean

          Force the event to be handled.

      Returns void

    • Protected

      Release any down keys when focusing a form element.

      Parameters

      • event: FocusEvent

        The focus event.

      Returns void

    • Private

      Reset tracking for which keys are in the down and released states

      Returns void

    • Private

      Handle a key press into the down position

      Parameters

      • event: KeyboardEvent

        The originating keyboard event

      • up: boolean

        A flag for whether the key is down or up

      Returns void

    • Emulates a key being pressed, triggering the Keyboard event workflow.

      Parameters

      • up: boolean

        If True, emulates the keyup Event. Else, the keydown event

      • code: string

        The KeyboardEvent#code which is being pressed

      • Optional options: {
            altKey: boolean;
            ctrlKey: boolean;
            shiftKey: boolean;
            repeat: boolean;
            force: boolean;
        } = {}

        Additional options to configure behavior.

        • altKey: boolean

          Emulate the ALT modifier as pressed

        • ctrlKey: boolean

          Emulate the CONTROL modifier as pressed

        • shiftKey: boolean

          Emulate the SHIFT modifier as pressed

        • repeat: boolean

          Emulate this as a repeat event

        • force: boolean

          Force the event to be handled.

      Returns KeyboardEventContext

    • Format a KeyboardEvent#code into a displayed string.

      Parameters

      • code: string

        The input code

      Returns string

      The displayed string for this code

    • Get a standardized keyboard context for a given event. Every individual keypress is uniquely identified using the KeyboardEvent#code property. A list of possible key codes is documented here: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values

      Parameters

      • event: KeyboardEvent

        The originating keypress event

      • up: boolean = false

        A flag for whether the key is down or up

      Returns KeyboardEventContext

      The standardized context of the event

    • Internal

      Given a standardized pressed key, find all matching registered Keybind Actions.

      Parameters

      • context: KeyboardEventContext

        A standardized keyboard event context

      Returns KeybindingAction[]

      The matched Keybind Actions. May be empty.

    • Private

      Converts a Keyboard Context event into a string representation, such as "C" or "Control+C"

      Parameters

      • context: KeyboardEventContext

        The standardized context of the event

      • includeModifiers: boolean = true

        If True, includes modifiers in the string representation

      Returns string

    • Private

      Test whether a keypress context matches the registration for a keybinding action

      Parameters

      • action: KeybindingAction

        The keybinding action

      • context: KeyboardEventContext

        The keyboard event context

      Returns boolean

      Does the context match the action requirements?

    • Private

      Given a registered Keybinding Action, executes the action with a given event and context

      Parameters

      • keybind: KeybindingAction

        The registered Keybinding action to execute

      • context: KeyboardEventContext

        The gathered context of the event

      Returns boolean

      Returns true if the keybind was consumed