Class KeycodeLayout

A concrete implementation of IKeyboardLayout based on keycodes.

The keyCode property of a 'keydown' event is a browser and OS specific representation of the physical key (not character) which was pressed on a keyboard. While not the most convenient API, it is currently the only one which works reliably on all browsers.

This class accepts a user-defined mapping of keycode to key, which allows for reliable shortcuts tailored to the user's system.

Implements

Constructors

  • Construct a new keycode layout.

    Parameters

    • name: string

      The human readable name for the layout.

    • codes: CodeMap

      A mapping of keycode to key value.

    • modifierKeys: string[] = []

      Array of modifier key names

    Returns KeycodeLayout

Properties

_codes: CodeMap
_keys: KeySet
_modifierKeys: KeySet
name: string

The human readable name of the layout.

Methods

  • Test whether the given key is a modifier key.

    Parameters

    • key: string

      The user provided key.

    Returns boolean

    true if the key is a modifier key, false otherwise.

  • Test whether the given key is a valid value for the layout.

    Parameters

    • key: string

      The user provided key to test for validity.

    Returns boolean

    true if the key is valid, false otherwise.

  • Get the key for a 'keydown' event.

    Parameters

    Returns string

    The associated key value, or an empty string if the event does not represent a valid primary key.

  • Get an array of the key values supported by the layout.

    Returns string[]

    A new array of the supported key values.