|
Download react-use/docs/useKeyboardJs.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 955 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useKeyboardJs.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useKeyboardJs.md
-
curl -L -o useKeyboardJs.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useKeyboardJs.md
955 Bytes
useKeyboardJs
React UI sensor hook that detects complex key combos like detecting when multiple keys are held down at the same time or requiring them to be held down in a specified order.
Via KeyboardJS key combos. Check its documentation for further details on how to make combo strings.
Usage
import useKeyboardJs from 'react-use/lib/useKeyboardJs';
const Demo = () => {
const [isPressed] = useKeyboardJs('a + b');
return (
<div>
[a + b] pressed: {isPressed ? 'Yes' : 'No'}
</div>
);
};
Note: Because of dependency on keyboardjs you have to import this hook directly like shown above.
Requirements
Install keyboardjs peer dependency:
npm add keyboardjs
# or
yarn add keyboardjs
Reference
useKeyboardJs(combination: string | string[]): [isPressed: boolean, event?: KeyboardEvent]