keys.ts 691 B

1234567891011121314151617181920212223242526272829
  1. export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
  2. export const KEYS =
  3. {
  4. ARROW_LEFT: "ArrowLeft",
  5. ARROW_RIGHT: "ArrowRight",
  6. ARROW_DOWN: "ArrowDown",
  7. ARROW_UP: "ArrowUp",
  8. ENTER: "Enter",
  9. ESCAPE: "Escape",
  10. DELETE: "Delete",
  11. BACKSPACE: "Backspace",
  12. CTRL_OR_CMD: isDarwin ? "metaKey" : "ctrlKey",
  13. TAB: "Tab",
  14. SPACE: " ",
  15. QUESTION_MARK: "?",
  16. F_KEY_CODE: 70,
  17. } as const;
  18. export type Key = keyof typeof KEYS;
  19. export function isArrowKey(keyCode: string) {
  20. return (
  21. keyCode === KEYS.ARROW_LEFT ||
  22. keyCode === KEYS.ARROW_RIGHT ||
  23. keyCode === KEYS.ARROW_DOWN ||
  24. keyCode === KEYS.ARROW_UP
  25. );
  26. }