mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-03 06:00:09 +00:00
15 lines
372 B
TypeScript
15 lines
372 B
TypeScript
import { useEffect } from "react";
|
|
|
|
export const useKeyPress = (key: string, callback: () => void) => {
|
|
useEffect(() => {
|
|
const handler = (e: KeyboardEvent) => {
|
|
if (e.key === key && e.altKey) {
|
|
callback();
|
|
}
|
|
};
|
|
window.addEventListener("keydown", handler);
|
|
return () => {
|
|
window.removeEventListener("keydown", handler);
|
|
};
|
|
}, [key, callback]);
|
|
};
|