globalShortcut
With globalShortcuts
it's possible to add shortcuts that are listened for globally.
Even if the application is not in focus the callbacks assign to the shortcuts will still execute.
import { globalShortcuts } from 'miletus';
globalShortcuts.add('CmdOrCtrl+K', () => {
console.log('Ctrl+K pressed!');
})
Note
Add global shortcuts in your main window only!
Supported keys
Key | Value |
---|---|
Ctrl | CmdOrCtrl |
Shift | Shift |
Alt | Alt |
A - Z | A - Z |
0 - 9 | 0 - 9 |
F1 - F24 | F1 - F24 |
Backspace | Backspace |
Tab | Tab |
Enter | Enter |
Esc | Esc |
Space | Space |
Page Up | PageUp |
Page Down | PageDown |
End | End |
Home | Home |
Left | Left |
Up | Up |
Right | Right |
Down | Down |
Ins | Insert |
Del | Delete |
For example: Ctrl+Shift+A equals to CmdOrCtrl+Shift+A
.
Methods
add(shortcut, callback)
- shortcut string - The shortcut to be listener for.
- callback Function - The callback that is called when the shortcut is pressed.
Add a shortcut to the listened shortcuts.
remove(shortcut)
shortcut
string - The shortcut to be removed.
Removes a shortcut from the listened shortcuts.
removeAll()
Removes all added shortcuts.