index.d.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. export interface HotkeysEvent {
  2. key: string;
  3. method: KeyHandler;
  4. mods: number[];
  5. scope: string;
  6. shortcut: string;
  7. }
  8. export interface KeyHandler {
  9. (keyboardEvent: KeyboardEvent, hotkeysEvent: HotkeysEvent): void | boolean;
  10. }
  11. type Options = {
  12. scope?: string;
  13. element?: HTMLElement | null;
  14. keyup?: boolean | null;
  15. keydown?: boolean | null;
  16. capture?: boolean
  17. splitKey?: string;
  18. }
  19. export interface Hotkeys {
  20. (key: string, method: KeyHandler): void;
  21. (key: string, scope: string, method: KeyHandler): void;
  22. (key: string, options: Options, method: KeyHandler): void;
  23. shift: boolean;
  24. ctrl: boolean;
  25. alt: boolean;
  26. option: boolean;
  27. control: boolean;
  28. cmd: boolean;
  29. command: boolean;
  30. keyMap: Record<string, number>;
  31. modifier: Record<string, number>;
  32. modifierMap: Record<string, number | string>;
  33. setScope(scopeName: string): void;
  34. getScope(): string;
  35. deleteScope(scopeName: string, newScopeName?: string): void;
  36. noConflict(): Hotkeys;
  37. trigger(shortcut: string, scope?: string): void;
  38. unbind(key?: string): void;
  39. unbind(key: string, scopeName: string): void;
  40. unbind(key: string, scopeName: string, method: KeyHandler): void;
  41. unbind(key: string, method: KeyHandler): void;
  42. isPressed(keyCode: number): boolean;
  43. isPressed(keyCode: string): boolean;
  44. getPressedKeyCodes(): number[];
  45. filter(event: KeyboardEvent): boolean;
  46. }
  47. // https://github.com/eiriklv/react-masonry-component/issues/57
  48. declare var hotkeys: Hotkeys;
  49. export default hotkeys;