mirror of
https://github.com/infinilabs/coco-app.git
synced 2026-09-02 12:15:39 +02:00
25 lines
642 B
TypeScript
25 lines
642 B
TypeScript
|
|
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"],
|
||
|
|
}
|
||
|
|
);
|
||
|
|
};
|