Interface IKeyboardLayout

An object which represents an abstract keyboard layout.

interface IKeyboardLayout {
    name: string;
    isModifierKey(key): boolean;
    isValidKey(key): boolean;
    keyForKeydownEvent(event): string;
    keys(): string[];
}

Implemented by

Properties

name: string

The human readable name of the layout.

This value is used primarily for display and debugging purposes.

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.

    Notes

    This is necessary so that we don't process modifier keys pressed in the middle of the key sequence. E.g. "Shift C Ctrl P" is actually 4 keydown events: "Shift", "Shift P", "Ctrl", "Ctrl P", and events for "Shift" and "Ctrl" should be ignored.

  • 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 all key values supported by the layout.

    Returns string[]

    A new array of the supported key values.

    Notes

    This can be useful for authoring tools and debugging, when it's necessary to know which keys are available for shortcut use.