mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-17 12:20:04 +00:00
15 lines
364 B
TypeScript
15 lines
364 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])
|
|
}
|