Global Hotkeys Api
GL.hotkeys
Section titled “GL.hotkeys”Accessors
Section titled “Accessors”pressed
Section titled “pressed”Get Signature
Section titled “Get Signature”get pressed():
Set<string>
Which key codes are currently being pressed
Returns
Section titled “Returns”Set<string>
Methods
Section titled “Methods”addConfigurableHotkey()
Section titled “addConfigurableHotkey()”addConfigurableHotkey(
id,options,callback): () =>void
Adds a hotkey which can be changed by the user
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
A unique id for the hotkey, such as myplugin-myhotkey |
options |
{ category: string; default: { alt: boolean; ctrl: boolean; key: string; keys: readonly string[]; shift: boolean; }; preventDefault: boolean; title: string; } |
- |
options.category |
string |
- |
options.default? |
{ alt: boolean; ctrl: boolean; key: string; keys: readonly string[]; shift: boolean; } |
- |
options.default.alt? |
boolean |
- |
options.default.ctrl? |
boolean |
- |
options.default.key? |
string |
Should be a keyboardevent code |
options.default.keys? |
readonly string[] |
Should be keyboardevent codes |
options.default.shift? |
boolean |
- |
options.preventDefault? |
boolean |
- |
options.title |
string |
There should be no duplicate titles within a category |
callback |
(e) => void |
- |
Returns
Section titled “Returns”Function
A function to remove the hotkey
Returns
Section titled “Returns”void
Example
Section titled “Example”GL.hotkeys.addConfigurableHotkey("MyPlugin-MyHotkey", { category: "My Plugin", title: "Do a thing", preventDefault: true, default: { key: "Digit1", ctrl: true, shift: true }}, (e) => { console.log("Configurable hotkey pressed", e.key);});addHotkey()
Section titled “addHotkey()”addHotkey(
id,options,callback): () =>void
Adds a hotkey with a given id
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
- |
options |
{ alt: boolean; ctrl: boolean; key: string; keys: readonly string[]; preventDefault: boolean; shift: boolean; } |
- |
options.alt? |
boolean |
- |
options.ctrl? |
boolean |
- |
options.key? |
string |
Should be a keyboardevent code |
options.keys? |
readonly string[] |
Should be keyboardevent codes |
options.preventDefault? |
boolean |
- |
options.shift? |
boolean |
- |
callback |
(e) => void |
- |
Returns
Section titled “Returns”Function
A function to remove the hotkey
Returns
Section titled “Returns”void
Example
Section titled “Example”GL.hotkeys.addHotkey("MyPlugin", { key: "Digit1", ctrl: true, shift: true, preventDefault: true}, (e) => { console.log("Hotkey pressed", e.key);});releaseAll()
Section titled “releaseAll()”releaseAll():
void
Releases all keys, needed if a hotkey opens something that will prevent keyup events from being registered, such as an alert
Returns
Section titled “Returns”void
removeConfigurableHotkey()
Section titled “removeConfigurableHotkey()”removeConfigurableHotkey(
id):void
Removes a configurable hotkey with a given id
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”void
removeHotkeys()
Section titled “removeHotkeys()”removeHotkeys(
id):void
Removes all hotkeys with a given id
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”void