Registers and handles keyboard shortcuts.
options
Options (optional)
Removes all shortcuts and other data. Unbinds the keydown handler if it was automatically attached (if the handler was attached manually it will not be automatically removed).
Returns string[]
- the contexts that are currently active
...contexts
string[] - the contexts to activate
Activates specified context names.
...contexts
string[] - new active contexts
Sets new active contexts, overriding the previous ones.
...contexts
string[] - the contexts to deactivate
Deactivates context(s)
shortcuts
ShortcutOptions[]
Adds new shortcuts.
removeShortcut(shortcut)
function - An anti-filter function that indicates whether the shortcut is to be removed.shortcut
Shortcut- Returns
boolean
indicating whether the shortcut is to be removed
keys
string | string[] (optional) - RunremoveShortcut
only for shortcuts registered for the particular keys rather than all, sparing unnecessary processing. The keys are case insensitive (unlike processing of Shortcut inremoveShortcut
!).
Returns number
- the number of shortcuts that have been removed.
Removes shortcuts that match the removeShortcut
anti-filter callback and optionally, keys
. It works opposite to the Array.prototype.filter
.
Use Shocut.modifiersMatch
to evaluate a shortcut by its modifiers.
NOTE: Single letter keys are always stored in upper case regardless of the original input data
and upper case letters must be used for comparison in removeShortcut
. In the majority of
cases it would just suffice to use the keys
argument which does not care about the case.
Returns boolean
- indicates whether any shortcut handler has fired.
It is used internally to handle keydown
on the window
target by default. If the noAutoBind
option has been set it must be called / bound manually to handle the event.
It is also possible to bind it to targets other than window
or even create multiple instances, each being bound to handle the keydown event on a different target.
Returns string
- 'ctrl'
or 'meta'
Gets the default modifier for keyboard shortcuts on the OS by reading data made available in window.navigator
This method is used by default if the systemMod
option is not set.
shortcut
Shortcutmodifiers
string[] - Array of modifiers. Use empty array to test for no modifiers.
Returns boolean
Checks whether modifiers
match those of the shortcut
. It is meant to be used in the .remove()
callback to remove shortcuts by their modifier.