shared
utils
string
object
is
extension
js
tracking
string
dom
when
selection
position
iframe
event
scroll
console
node
string
project
fs
console
hotkey
Type:Function
Status:stable
Since:1.0.0
Platform:js
@blackbyte.sugar.js.keyboard
This function allows you to register a hotkey on the passed element. You can specify the hotkey using the following syntax:
ctrl+ashift+ctrl+aaThis function take care of avoiding to call your callback when the active element is an input, a textarea or an editable content with the “contenteditable” attribute, unless:- the “meta” or “ctrl” key is used in the hotkey.
- the pressed key is the “escape” key.
Params
- key*-String|String[]
The key(s) to listen for
- callback*-Function
The callback to call when the hotkey is pressed
- settings{}THotkeySettings
Some settings to configure your hotkey
Return
- -THotkeyApi
An object with a cancel method that you can call to cancel the hotkey
Example
import { hotkey } from '@blackbyte/sugar/keyboard'
const hotkeyApi = hotkey('ctrl+a', (e) => {
console.log('Hotkey pressed');
});
// if you want to cancel the hotkey
hotkeyApi.cancel();Settings
- ctxdocument.bodyHTMLElement
The context in which to listen for the hotkey
- preventDefaulttrueBoolean
Specify if you want to prevent the default behavior of the hotkey
Todo
- testsnormal
Author
- Olivier Bosselolivier.bossel@gmail.comhttps://blackbyte.space