@tauri-apps/plugin-global-shortcut
Register global shortcuts.
Interfaces
ShortcutEvent
Properties
Property | Type |
---|---|
id | number |
shortcut | string |
state | "Released" | "Pressed" |
Type Aliases
ShortcutHandler()
type ShortcutHandler: (event) => void;
Parameters
Parameter | Type |
---|---|
event | ShortcutEvent |
Returns
void
Functions
isRegistered()
function isRegistered(shortcut): Promise<boolean>
Determines whether the given shortcut is registered by this application or not.
If the shortcut is registered by another application, it will still return false
.
Parameters
Parameter | Type | Description |
---|---|---|
shortcut | string | shortcut definition, modifiers and key separated by ”+” e.g. CmdOrControl+Q |
Returns
Promise
<boolean
>
Example
import { isRegistered } from '@tauri-apps/plugin-global-shortcut';const isRegistered = await isRegistered('CommandOrControl+P');
Since
2.0.0
register()
function register(shortcut, handler): Promise<void>
Register a global shortcut.
Parameters
Parameter | Type | Description |
---|---|---|
shortcut | string | Shortcut definition, modifiers and key separated by ”+” e.g. CmdOrControl+Q |
handler | ShortcutHandler | Shortcut handler callback - takes the triggered shortcut as argument |
Returns
Promise
<void
>
Example
import { register } from '@tauri-apps/plugin-global-shortcut';await register('CommandOrControl+Shift+C', (event) => { if (event.state === "Pressed") { console.log('Shortcut triggered'); }});
Since
2.0.0
registerAll()
function registerAll(shortcuts, handler): Promise<void>
Register a collection of global shortcuts.
Parameters
Parameter | Type | Description |
---|---|---|
shortcuts | string [] | Array of shortcut definitions, modifiers and key separated by ”+” e.g. CmdOrControl+Q |
handler | ShortcutHandler | Shortcut handler callback - takes the triggered shortcut as argument |
Returns
Promise
<void
>
Example
import { registerAll } from '@tauri-apps/plugin-global-shortcut';await registerAll(['CommandOrControl+Shift+C', 'Ctrl+Alt+F12'], (event) => { console.log(`Shortcut ${event.shortcut} ${event.state}`);});
Since
2.0.0
unregister()
function unregister(shortcut): Promise<void>
Unregister a global shortcut.
Parameters
Parameter | Type | Description |
---|---|---|
shortcut | string | shortcut definition, modifiers and key separated by ”+” e.g. CmdOrControl+Q |
Returns
Promise
<void
>
Example
import { unregister } from '@tauri-apps/plugin-global-shortcut';await unregister('CmdOrControl+Space');
Since
2.0.0
unregisterAll()
function unregisterAll(): Promise<void>
Unregisters all shortcuts registered by the application.
Returns
Promise
<void
>
Example
import { unregisterAll } from '@tauri-apps/plugin-global-shortcut';await unregisterAll();
Since
2.0.0
© 2024 Tauri Contributors. CC-BY / MIT