You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts. Uses a fork of hotkeys.js for keydown detection of special characters. You give it a keymap of shortcuts & it bind it to the mousetrap singleton. The, it'll unbind it when the component unmounts.
react-hotkeys-hook - React hook for using keyboard shortcuts in components. Make sure that you have at least version 16.8 of react and react-dom installed, or otherwise hooks won't work for you.
importReactfrom'react';importHotkeysfrom'react-hot-keys';exportdefaultclassHotkeysDemoextendsReact.Component{constructor(props){super(props);this.state={output: 'Hello, I am a component that listens to keydown and keyup of a',}}onKeyUp(keyName,e,handle){console.log("test:onKeyUp",e,handle)this.setState({output: `onKeyUp ${keyName}`,});}onKeyDown(keyName,e,handle){console.log("test:onKeyDown",keyName,e,handle)this.setState({output: `onKeyDown ${keyName}`,});}render(){return(<HotkeyskeyName="shift+a,alt+s"onKeyDown={this.onKeyDown.bind(this)}onKeyUp={this.onKeyUp.bind(this)}><divstyle={{padding: "50px"}}>{this.state.output}</div></Hotkeys>)}}