16 lines
351 B
TypeScript
16 lines
351 B
TypeScript
export type KeyUpCallback = (key: string) => void;
|
|
|
|
export const useKeyUp = (callback: KeyUpCallback) => {
|
|
const handleKeyUp = (event: KeyboardEvent) => {
|
|
callback(event.key);
|
|
};
|
|
|
|
onMounted(() => {
|
|
window.addEventListener("keyup", handleKeyUp);
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
window.removeEventListener("keyup", handleKeyUp);
|
|
});
|
|
};
|