The constructor.
Optional element?: typeof globalThis | HTMLElement | Window(optional) The HTML element to listen on; if null then 'window' will be used.
Optional track(optional) Set to true if you want to keep track of all keys (keyStatus).
KeyHandler
Private _keyPrivate _keyPrivate _keyPrivate downPrivate elementPrivate keyPrivate pressPrivate trackPrivate upStatic Private KEY_Source: https://keycode.info/
Listen for key down. This function allows chaining.
Example: new KeyHandler().down('enter',function() {console.log('Enter hit.')});
Any key identifier, key code or one from the KEY_CODES list.
this
down
KeyHandler
Private firePrivate Internal function to fire a new keydown event to all listeners. You should not call this function on your own unless you know what you do.
fireDownEvent
KeyHandler
Private fireA helper function to fire key events from this KeyHandler.
The key event to fire.
Private firePrivate Internal function to fire a new keypress event to all listeners. You should not call this function on your own unless you know what you do.
void
firePressEvent
KeyHandler
Private firePrivate Internal function to fire a new keyup event to all listeners. You should not call this function on your own unless you know what you do.
fireUpEvent
KeyHandler
Listen for key press.
Example: new KeyHandler().press('enter',function() {console.log('Enter pressed.')});
Any key identifier, key code or one from the KEY_CODES list.
The callback to be triggered.
this
press
KeyHandler
Listen for key up.
Example: new KeyHandler().up('enter',function() {console.log('Enter released.')});
Any key identifier, key code or one from the KEY_CODES list.
this
up
KeyHandler
Static key2code
Classdesc
A generic key handler.
Example
Example