Files
coco-app/src/hooks/useModifierKeyPress.ts

25 lines
642 B
TypeScript
Raw Normal View History

import { modifierKeys } from "@/components/Settings/Advanced/components/Shortcuts";
import { useShortcutsStore } from "@/stores/shortcutsStore";
import { useKeyPress } from "ahooks";
export const useModifierKeyPress = () => {
const modifierKey = useShortcutsStore((state) => {
return state.modifierKey;
});
const setModifierKeyPressed = useShortcutsStore((state) => {
return state.setModifierKeyPressed;
});
useKeyPress(
modifierKeys,
(event, key) => {
if (key === modifierKey) {
setModifierKeyPressed(event.type === "keydown");
}
},
{
events: ["keydown", "keyup"],
}
);
};