@phosphor/keyboard

  • Version 1.1.3
  • Published
  • 11.8 kB
  • No dependencies
  • BSD-3-Clause license

Install

npm i @phosphor/keyboard
yarn add @phosphor/keyboard
pnpm add @phosphor/keyboard

Overview

PhosphorJS - Keyboard

Index

Variables

variable EN_US

const EN_US: IKeyboardLayout;
  • A keycode-based keyboard layout for US English keyboards.

    This layout is valid for the following OS/Browser combinations.

    - Windows - Chrome - Firefox - IE

    - OSX - Chrome - Firefox - Safari

    - Linux - Chrome - Firefox

    Other combinations may also work, but are untested.

Functions

function getKeyboardLayout

getKeyboardLayout: () => IKeyboardLayout;
  • Get the global application keyboard layout instance.

    Returns

    The keyboard layout for use by the application.

    #### Notes The default keyboard layout is US-English.

function setKeyboardLayout

setKeyboardLayout: (layout: IKeyboardLayout) => void;
  • Set the global application keyboard layout instance.

    Parameter

    - The keyboard layout for use by the application.

    #### Notes The keyboard layout should typically be set on application startup to a layout which is appropriate for the user's system.

Classes

class KeycodeLayout

class KeycodeLayout implements IKeyboardLayout {}
  • 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.

constructor

constructor(name: string, codes: KeycodeLayout.CodeMap);
  • Construct a new keycode layout.

    Parameter name

    The human readable name for the layout.

    Parameter codes

    A mapping of keycode to key value.

property name

readonly name: string;
  • The human readable name of the layout.

method isValidKey

isValidKey: (key: string) => boolean;
  • Test whether the given key is a valid value for the layout.

    Parameter key

    The user provided key to test for validity.

    Returns

    true if the key is valid, false otherwise.

method keyForKeydownEvent

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

    Parameter event

    The event object for a 'keydown' event.

    Returns

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

method keys

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

    Returns

    A new array of the supported key values.

Interfaces

interface IKeyboardLayout

interface IKeyboardLayout {}
  • An object which represents an abstract keyboard layout.

property name

readonly name: string;
  • The human readable name of the layout.

    This value is used primarily for display and debugging purposes.

method isValidKey

isValidKey: (key: string) => boolean;
  • Test whether the given key is a valid value for the layout.

    Parameter key

    The user provided key to test for validity.

    Returns

    true if the key is valid, false otherwise.

method keyForKeydownEvent

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

    Parameter event

    The event object for a 'keydown' event.

    Returns

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

method keys

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

    Returns

    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.

Namespaces

namespace KeycodeLayout

namespace KeycodeLayout {}
  • The namespace for the KeycodeLayout class statics.

function extractKeys

extractKeys: (codes: CodeMap) => KeySet;
  • Extract the set of keys from a code map.

    Parameter code

    The code map of interest.

    Returns

    A set of the keys in the code map.

type CodeMap

type CodeMap = {
readonly [code: number]: string;
};
  • A type alias for a keycode map.

type KeySet

type KeySet = {
readonly [key: string]: boolean;
};
  • A type alias for a key set.

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (15)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@phosphor/keyboard.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@phosphor/keyboard)
  • HTML
    <a href="https://www.jsdocs.io/package/@phosphor/keyboard"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>