Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 818 Bytes

useKeyboardJs.md

File metadata and controls

41 lines (28 loc) · 818 Bytes

useKeyboardJs

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

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

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

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

Usage

import useKeyboardJs from 'react-use/lib/useKeyboardJs';

const Demo = () => {
  const [isPressed] = useKeyboardJs('a + b');

  return (
    <div>
      [a + b] pressed: {isPressed ? 'Yes' : 'No'}
    </div>
  );
};

Requirements

Install keyboardjs peer dependency:

npm add keyboardjs
# or
yarn add keyboardjs

Reference

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