Constructor
Handle key combination events.
JavaScript:
-
new Coral.Keys()
- Parameters:
-
Name Type Optional Description elOrSelector * No
The selector or element to listen for keyboard events on. This should be the common parent of all elements you wish to listen for events on. options Object Yes
Options for this combo handler.
Name Type Optional Default Description options.context function Yes
The desired value of the this
keyword context when executing listeners. Defaults to the element on which the event is listened for.options.preventDefault function Yes
Whether to prevent the default behavior when a key combo is matched. options.stopPropagation function Yes
Whether to stop propagation when a key combo is matched. options.filter function Yes
Coral.Keys.filterInputs The filter function for keyboard events. This can be used to stop events from being triggered when they originate from specific elements.
Static Properties
-
Coral.Keys.sequenceTime {Number}
-
- Default Value:
- 1500
The time allowed between keypresses for a sequence in miliseconds
Methods
-
Coral.Keys.filterInputs
-
- Parameters:
-
Name Type Description event The event passed - Returns:
-
True, if event.target is not editable and event.target.tagname is not restricted {Boolean}
-
Coral.Keys.keyToCode
-
- Parameters:
-
Name Type Description key String The key character that needs to be converted. If the String contains more than one character, an error will be produced. - Returns:
-
The character code of the given String. {Number}
-
instance.destroy
-
- Parameters:
-
Name Type Description globalsOnly Boolean Whether only global listeners should be removed - Returns:
-
this, chainable. {Coral.Keys}
-
instance.init
-
- Parameters:
-
Name Type Description globalsOnly Boolean Whether only global listeners should be added - Returns:
-
this, chainable. {Coral.Keys}
-
instance.off
-
- Parameters:
-
Name Type Optional Description keyCombo String No
The key combination to listen for, such as 'ctrl-f'
.selector String Yes
A selector to use for event delegation. listener function No
The listener that was passed to on. - Returns:
-
this, chainable. {Coral.Keys}
-
instance.on
-
- Parameters:
-
Name Type Optional Description keyCombo String No
The key combination to listen for, such as 'ctrl-f'
.selector String Yes
A selector to use for event delegation. data String Yes
Data to pass to listeners as event.data
.listener function No
The listener to execute when this key combination is pressed. Executes on keydown, or, if too many keys are pressed and one is released, resulting in the correct key combination, executes on keyup. - Returns:
-
this, chainable. {Coral.Keys}
-
instance.reset
-
- Returns:
-
this, chainable. {Coral.Keys}
The default keycombo event filter function. Ignores key combos triggered on input, select, and textarea.
Convert a key to its character code representation.
Destroy this instance. This removes all event listeners, references, and state.
Initialize an instance created without the
new
keyword or revive a destroyed instance. This method
will be called automatically if an instance is created with new Coral.keys
, but otherwise will not be
called.
Remove a key combo listener.
Add a key combo listener.
Reset the state of this instance. This resets the currently pressed keys.