Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KeycodeLayout

A concrete implementation of IKeyboardLayout based on keycodes. The namespace for the KeycodeLayout class statics.

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.

Hierarchy

  • KeycodeLayout

Implements

Index

Type aliases

Static CodeMap

CodeMap: object

A type alias for a keycode map.

Type declaration

  • [code: number]: string

Static KeySet

KeySet: object

A type alias for a key set.

Type declaration

  • [key: string]: boolean

Constructors

constructor

  • Construct a new keycode layout.

    Parameters

    • name: string

      The human readable name for the layout.

    • codes: CodeMap

      A mapping of keycode to key value.

    • Default value modifierKeys: string[] = []

      Array of modifier key names

    Returns KeycodeLayout

Properties

Private _codes

_codes: CodeMap

Private _keys

_keys: KeySet

Private _modifierKeys

_modifierKeys: KeySet

name

name: string

The human readable name of the layout.

Methods

isModifierKey

  • isModifierKey(key: string): boolean
  • 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.

isValidKey

  • isValidKey(key: string): boolean
  • 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.

keyForKeydownEvent

  • keyForKeydownEvent(event: KeyboardEvent): string
  • Get the key for a 'keydown' event.

    Parameters

    • event: KeyboardEvent

      The event object for a 'keydown' event.

    Returns string

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

keys

  • keys(): string[]
  • Get an array of the key values supported by the layout.

    Returns string[]

    A new array of the supported key values.

Static convertToKeySet

  • convertToKeySet(keys: string[]): KeySet
  • Convert array of keys to a key set.

    Parameters

    • keys: string[]

      The array that needs to be converted

    Returns KeySet

    A set of the keys in the array.

Static extractKeys

  • Extract the set of keys from a code map.

    Parameters

    Returns KeySet

    A set of the keys in the code map.

Generated using TypeDoc