globalShortcut.d.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. export type ShortcutHandler = (shortcut: string) => void;
  2. /**
  3. * Register a global shortcut.
  4. * @example
  5. * ```typescript
  6. * import { register } from '@tauri-apps/api/globalShortcut';
  7. * await register('CommandOrControl+Shift+C', () => {
  8. * console.log('Shortcut triggered');
  9. * });
  10. * ```
  11. *
  12. * @param shortcut Shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q
  13. * @param handler Shortcut handler callback - takes the triggered shortcut as argument
  14. *
  15. * @since 1.0.0
  16. */
  17. declare function register(shortcut: string, handler: ShortcutHandler): Promise<void>;
  18. /**
  19. * Register a collection of global shortcuts.
  20. * @example
  21. * ```typescript
  22. * import { registerAll } from '@tauri-apps/api/globalShortcut';
  23. * await registerAll(['CommandOrControl+Shift+C', 'Ctrl+Alt+F12'], (shortcut) => {
  24. * console.log(`Shortcut ${shortcut} triggered`);
  25. * });
  26. * ```
  27. *
  28. * @param shortcuts Array of shortcut definitions, modifiers and key separated by "+" e.g. CmdOrControl+Q
  29. * @param handler Shortcut handler callback - takes the triggered shortcut as argument
  30. *
  31. * @since 1.0.0
  32. */
  33. declare function registerAll(shortcuts: string[], handler: ShortcutHandler): Promise<void>;
  34. /**
  35. * Determines whether the given shortcut is registered by this application or not.
  36. * @example
  37. * ```typescript
  38. * import { isRegistered } from '@tauri-apps/api/globalShortcut';
  39. * const isRegistered = await isRegistered('CommandOrControl+P');
  40. * ```
  41. *
  42. * @param shortcut Array of shortcut definitions, modifiers and key separated by "+" e.g. CmdOrControl+Q
  43. *
  44. * @since 1.0.0
  45. */
  46. declare function isRegistered(shortcut: string): Promise<boolean>;
  47. /**
  48. * Unregister a global shortcut.
  49. * @example
  50. * ```typescript
  51. * import { unregister } from '@tauri-apps/api/globalShortcut';
  52. * await unregister('CmdOrControl+Space');
  53. * ```
  54. *
  55. * @param shortcut shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q
  56. *
  57. * @since 1.0.0
  58. */
  59. declare function unregister(shortcut: string): Promise<void>;
  60. /**
  61. * Unregisters all shortcuts registered by the application.
  62. * @example
  63. * ```typescript
  64. * import { unregisterAll } from '@tauri-apps/api/globalShortcut';
  65. * await unregisterAll();
  66. * ```
  67. *
  68. * @since 1.0.0
  69. */
  70. declare function unregisterAll(): Promise<void>;
  71. export { register, registerAll, isRegistered, unregister, unregisterAll };