Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • KeyboardManager

Index

Constructors

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: Object = ...

    An 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 a Form Element currently has focus

      Returns boolean

    Methods

    • isModifierActive(modifier: string): boolean
    • 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)?

    • _onCompositionEnd(event: CompositionEvent): void
    • _processKeyboardContext(context: KeyboardEventContext): void
    • Processes a keyboard event context, checking it against registered keybinding actions

      Parameters

      • context: KeyboardEventContext

        The keyboard event context

      Returns void

    • _reset(): void
    • Reset tracking for which keys are in the down and released states

      Returns void

    • _handleKeyboardEvent(event: KeyboardEvent, up: boolean): void
    • 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

    • emulateKeypress(up: boolean, code: string, __namedParameters?: boolean): KeyboardEventContext
    • 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

      • __namedParameters: boolean = {}

      Returns KeyboardEventContext

    • getKeycodeDisplayString(code: string): string
    • Format a KeyboardEvent#code into a displayed string.

      Parameters

      • code: string

        The input code

      Returns string

      The displayed string for this code

    • getKeyboardEventContext(event: KeyboardEvent, up?: boolean): KeyboardEventContext
    • 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

    • _getMatchingActions(context: KeyboardEventContext): KeybindingAction[]
    • Given a standardized pressed key, find all matching registered Keybind Actions.

      internal

      Parameters

      • context: KeyboardEventContext

        A standardized keyboard event context

      Returns KeybindingAction[]

      The matched Keybind Actions. May be empty.

    • _getContextDisplayString(context: KeyboardEventContext, includeModifiers?: boolean): string
    • 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

    • _testContext(action: KeybindingAction, context: KeyboardEventContext): boolean
    • 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?

    • _executeKeybind(keybind: KeybindingAction, context: KeyboardEventContext): boolean
    • 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