Skip to main content

KeyboardDevice

Classes

Provides keyboard input. Listens for key events on a DOM element and provides signals and state for key presses. NOTE: when losing focus of the application, any "pressed" keys will be automatically released. For example, if you hold "A" and click over into another application window - A will be forcibly released with appropriate signal.

Members

  • down : Signal.<KeyboardEvent>

Fires when any key is pressed

  • up : Signal.<KeyboardEvent>

Fires when any key is released

Constants

KeyboardDevice

Provides keyboard input. Listens for key events on a DOM element and provides signals and state for key presses. NOTE: when losing focus of the application, any "pressed" keys will be automatically released. For example, if you hold "A" and click over into another application window - A will be forcibly released with appropriate signal.

Kind: global class
Author: Alex Goldring
Copyright: Company Named Limited (c) 2025

new KeyboardDevice(domElement)

Throws:

  • TypeError If the provided domElement is not focusable and doesn't have a tabindex attribute.
ParamTypeDescription
domElementEventTarget | ElementThe DOM element to listen for keyboard events on. This element must be focusable (e.g., have a tabindex attribute).

keyboardDevice.on

Kind: instance property of KeyboardDevice
Read only: true

keyboardDevice.keys : Object.<InputDeviceSwitch>

See KeyCodes for valid IDs

Kind: instance property of KeyboardDevice
Read only: true
Example

const is_enter_pressed = keyboard.keys.enter.is_down;

keyboardDevice.domElement : EventTarget

The DOM element being listened to.

Kind: instance property of KeyboardDevice

keyboardDevice.start() ⇒ void

Starts listening for keyboard events on the associated DOM element.

Kind: instance method of KeyboardDevice

keyboardDevice.stop() ⇒ void

Stops listening for keyboard events.

Kind: instance method of KeyboardDevice

down : Signal.<KeyboardEvent>

Fires when any key is pressed

Kind: global variable

up : Signal.<KeyboardEvent>

Fires when any key is released

Kind: global variable

codeToKeyNameMap : Array.<string>

Kind: global constant
Read only: true