import { onMounted, onUnmounted, ref } from 'vue';

type QueryKey = string | number | null;

export function useCurrentKey() {
  const currentKey = ref<string | null>(null);

  const handleKeydown = (event: KeyboardEvent) => {

    const key = event.key;
    currentKey.value = key;
};

const handleKeyup = () => {
    currentKey.value = null;
  }

  onMounted(() => {
    addEventListener('keydown', handleKeydown);
    addEventListener('keyup', handleKeyup);
  });

  onUnmounted(() => {
    removeEventListener('keydown', handleKeydown);
    removeEventListener('keyup', handleKeyup);
  });

  return currentKey;
}
