The constructor.
(optional) The HTML element to listen on; if null then 'window' will be used.
(optional) Set to true if you want to keep track of all keys (keyStatus).
This function should invalidate any installed listeners and invalidate this object. After calling this function the object might not hold valid data any more and should not be used any more.
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
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.
A helper function to fire key events from this KeyHandler.
The key event to fire.
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
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.
Install the required listeners into the initially passed element.
By default the listeners are installed into the root element specified on construction (or 'window').
Check if a specific key is currently held pressed.
Any key identifier, key code or one from the KEY_CODES list.
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
Remove all installed event listeners from the underlying element.
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
Resolve the key/name code.
Source: https://keycode.info/
Generated using TypeDoc
A generic key handler.
Example
// Javascript new KeyHandler( { trackAll : true } ) .down('enter',function() { console.log('ENTER was hit.'); } ) .press('enter',function() { console.log('ENTER was pressed.'); } ) .up('enter',function() { console.log('ENTER was released.'); } ) .down('e',function() { console.log('e was hit. shift is pressed?',keyHandler.isDown('shift')); } ) .up('windows',function() { console.log('windows was released.'); } ) ;