Class: KeyboardHandler
input/keyboard.KeyboardHandler
Handles keyboard events for an {@link HTMLElement}.
Constructors
constructor
โข new KeyboardHandler(element
)
Parameters
Name | Type |
---|---|
element | HTMLElement |
Defined in
src/input/keyboard.ts:15
Properties
element
โข Readonly
element: HTMLElement
Defined in
src/input/keyboard.ts:10
keys
โข keys: Object
= {}
Index signature
โช [index: string
]: boolean
Defined in
src/input/keyboard.ts:12
listeners
โข listeners: Object
= {}
Index signature
โช [index: string
]: KeyCallback
[]
Defined in
src/input/keyboard.ts:13
Methods
addListener
โธ addListener(code
, cb
): void
Attaches a listener to a given key code that is called whenever the state of the key changes.
Parameters
Name | Type | Description |
---|---|---|
code | string | The key code to attach the listener to |
cb | KeyCallback | The callback to execute on a keydown/keyup event |
Returns
void
Defined in
src/input/keyboard.ts:71
addListeners
โธ Private
addListeners(): void
Returns
void
Defined in
src/input/keyboard.ts:24
isPressed
โธ isPressed(code
): boolean
Determines wether or not a key is currently pressed.
see
Key Codes
Parameters
Name | Type | Description |
---|---|---|
code | string | The key code to check |
Returns
boolean
Wether or not the key corresponding to the given code is pressed.
Defined in
src/input/keyboard.ts:44
removeListener
โธ removeListener(code
, cb
): void
Removes a listener from a given key code.
Parameters
Name | Type | Description |
---|---|---|
code | string | The key code the listener is attached to |
cb | KeyCallback | The attached listener |
Returns
void
Defined in
src/input/keyboard.ts:85
setKey
โธ setKey(code
, pressed
): void
Emulates a keydown/keyup event on the pages body for a given key code.
see
Key Codes
Parameters
Name | Type | Description |
---|---|---|
code | string | The key code to emulate |
pressed | boolean | When true a keydown event is emulated otherwise keyup is emulated |
Returns
void
Defined in
src/input/keyboard.ts:56