1.2.0 • Published 18 days ago

react-use-record-hotkey v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
18 days ago

react-use-record-hotkey

录制键盘快捷键 Hook

NPM version NPM downloads install size

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;
1.2.0

18 days ago

1.1.0

19 days ago

1.0.1

2 months ago

1.0.0

2 months ago

1.0.0-beta.1

2 months ago