react-use-record-hotkey
v1.2.0
Published
> 录制键盘快捷键 Hook
Downloads
234
Maintainers
Readme
react-use-record-hotkey
录制键盘快捷键 Hook
Install
npm i react-use-record-hotkey -S
Usage
import { useRecordHotkey } from 'react-use-record-hotkey';
const App = () => {
const [inputRef, keys, { start, stop, isRecording }] = useRecordHotkey({
onClean: () => {
console.log('Clean');
},
onConfirm: (hotkey) => {
console.log(`Hotkey: ${Array.from(hotkey).join('+')}`);
},
});
const hotkey = Array.from(keys).join('+');
return (
<div>
<input ref={inputRef} autoFocus readOnly value={hotkey} />
<button onClick={start}>Start</button>
<button onClick={stop}>Stop</button>
<p>Recording: {isRecording ? 'Yes' : 'No'}</p>
<p>Hotkey: {hotkey}</p>
</div>
);
};
export default App;