export type KeyDownCallback = (key: string) => void;

export const useKeyDown = (callback: KeyDownCallback) => {
  const handleKeyDown = (event: KeyboardEvent) => {
    callback(event.key);
  };

  onMounted(() => {
    window.addEventListener("keydown", handleKeyDown);
  });

  onUnmounted(() => {
    window.removeEventListener("keydown", handleKeyDown);
  });
};
