react-use-record-hotkey
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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;

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i react-use-record-hotkey

      Weekly Downloads

      3

      Version

      1.2.0

      License

      MIT

      Unpacked Size

      21.9 kB

      Total Files

      14

      Last publish

      Collaborators

      • wxh16144