Hotkeys Module
Required Permissions: slobs.hotkeys
This module allows your app to register a listener for global hotkeys. These hotkeys are registered with the operating system, and will be triggered regardless of what application is currently in focus. Currently these keybindings are not persisted anywhere. Your app is responsible for binding these on startup each time. Your page should run in persistent
mode if you want to be able to respond to hotkeys when your app page is not in focus.
Minimum Version
This was module was added in Build 8
of the Streamlabs OBS App Developer build.
KeyReference object
object
Property | Type | Description |
---|---|---|
type | up | down | Whether this refers to a key-up or key-down listener. If you are implementing momentary-press hotkey, then you should bind behavior on both up and down. |
key | string | The key code of the key you want to bind. This is the same as the event.code string that is provided by DOM KeyboardEvent listeners. For a full list of available keys, look here |
modifiers | a KeyModifiers object | The modifiers for this listener. |
KeyModifiers object
object
Property | Type | Description |
---|---|---|
alt | boolean (default = false) | Whether this hotkey requires the alt key modifier. |
ctrl | boolean (default = false) | Whether this hotkey requires the ctrl key modifier. |
meta | boolean (default = false) | Whether this hotkey requires the meta (win) key modifier. |
shift | boolean (default = false) | Whether this hotkey requires the shift key modifier. |
registerKey method
method
registerKey(keyReference: KeyReference, callback: Function): boolean
Registers a hotkey for your app.
Arguments
keyReference
: A Key Reference object.callback
: A callback function that will be called when the key is pressed
Returns
This function returns true
if the callback was successfully bound, otherwise it returns false
.
Example
streamlabsOBS.v1.Hotkeys.registerKey(
{
type: 'up',
key: 'KeyF',
modifiers: {
alt: true,
shift: true
}
},
() => console.log('Key Pressed!')
);
unregisterKey method
method
unregisterKey(keyReference: KeyReference): void
Unregisters your callback for the given reference.
Arguments
keyReference
: A Key Reference object.
Returns
None
Example
streamlabsOBS.v1.Hotkeys.unregisterKey(
{
type: 'up',
key: 'KeyF',
modifiers: {
alt: true,
shift: true
}
}
);
unregisterAll method
method
unregisterAll(): void
This method will unregister all keys for your app.
streamlabsOBS.v1.Hotkeys.unregisterAll()
Updated about 6 years ago