keys.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
  2. export const KEYS = {
  3. ARROW_LEFT: "ArrowLeft",
  4. ARROW_RIGHT: "ArrowRight",
  5. ARROW_DOWN: "ArrowDown",
  6. ARROW_UP: "ArrowUp",
  7. ENTER: "Enter",
  8. ESCAPE: "Escape",
  9. DELETE: "Delete",
  10. BACKSPACE: "Backspace",
  11. CTRL_OR_CMD: isDarwin ? "metaKey" : "ctrlKey",
  12. TAB: "Tab",
  13. SPACE: " ",
  14. QUESTION_MARK: "?",
  15. F_KEY_CODE: 70,
  16. ALT_KEY_CODE: 18,
  17. Z_KEY_CODE: 90,
  18. GRID_KEY_CODE: 222,
  19. H_KEY_CODE: 72,
  20. G_KEY_CODE: 71,
  21. C_KEY_CODE: 67,
  22. V_KEY_CODE: 86,
  23. } as const;
  24. export type Key = keyof typeof KEYS;
  25. export const isArrowKey = (keyCode: string) =>
  26. keyCode === KEYS.ARROW_LEFT ||
  27. keyCode === KEYS.ARROW_RIGHT ||
  28. keyCode === KEYS.ARROW_DOWN ||
  29. keyCode === KEYS.ARROW_UP;
  30. export const getResizeCenterPointKey = (event: MouseEvent | KeyboardEvent) =>
  31. event.altKey || event.which === KEYS.ALT_KEY_CODE;
  32. export const getResizeWithSidesSameLengthKey = (event: MouseEvent) =>
  33. event.shiftKey;
  34. export const getRotateWithDiscreteAngleKey = (event: MouseEvent) =>
  35. event.shiftKey;