excalidraw/src/keys.ts

29 lines
661 B
TypeScript
Raw Normal View History

export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
export const KEYS = {
ARROW_LEFT: "ArrowLeft",
ARROW_RIGHT: "ArrowRight",
ARROW_DOWN: "ArrowDown",
ARROW_UP: "ArrowUp",
ENTER: "Enter",
ESCAPE: "Escape",
DELETE: "Delete",
BACKSPACE: "Backspace",
CTRL_OR_CMD: isDarwin ? "metaKey" : "ctrlKey",
TAB: "Tab",
SPACE: " ",
QUESTION_MARK: "?",
F_KEY_CODE: 70,
} as const;
2020-03-23 16:38:41 -07:00
export type Key = keyof typeof KEYS;
export function isArrowKey(keyCode: string) {
return (
keyCode === KEYS.ARROW_LEFT ||
keyCode === KEYS.ARROW_RIGHT ||
keyCode === KEYS.ARROW_DOWN ||
keyCode === KEYS.ARROW_UP
);
}