KeyDown

View source

Captures the keyboard data from a browser keydown event.

Construct this value from the event when handling keyboard input. It keeps the key identity, physical code, keyboard location, target, and the runtime scancode alias.

Examples

const down = new KeyDown(new KeyboardEvent('keydown', {
  key: 'a',
  code: 'KeyA'
}))

console.log(down.key, down.code, down.scancode) // a KeyA KeyA

Constructor


constructor(event: KeyboardEvent)

View source

Copies key, code, location, and target from the browser event. It also assigns event.code to the runtime scancode property, even though scancode is not declared as a class field.

Parameters

NameDescriptionDefault
event

Browser keyboard event to capture.

—

Properties


scancode: string

View source

Runtime property assigned from event.code; it is not declared as a class field.