Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 843 Bytes

useKeyboardJs.md

File metadata and controls

39 lines (28 loc) · 843 Bytes

useKeyboardJs

React UI sensor hook that detects complex key combos like detecting when multiple keys are held down at the same time or requiring them to be held down in a specified order.

Via KeyboardJS key combos. Check its documentation for further details on how to make combo strings.

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]