useKeyboardJs

React UI传感器钩子,可检测复杂的键组合,如检测时间

多个键同时按下或要求按指定的顺序按下它们。

通过[KeyboardJS键组合](https://github.com/RobertWHurst/KeyboardJS)。

有关如何制作组合字符串的更多详细信息,请查看其文档。

Usage

  1. import useKeyboardJs from 'react-use/lib/useKeyboardJs';
  2. const Demo = () => {
  3. const [isPressed] = useKeyboardJs('a + b');
  4. return (
  5. <div>
  6. [a + b] pressed: {isPressed ? 'Yes' : 'No'}
  7. </div>
  8. );
  9. };

Requirements

Install keyboardjs peer dependency:

  1. npm add keyboardjs
  2. # or
  3. yarn add keyboardjs

Reference

  1. useKeyboardJs(combination: string): [isPressed: boolean, event?: KeyboardEvent]