Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.

NotificationsYou must be signed in to change notification settings

jaywcjlove/react-hotkeys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM DownloadsCInpm packageCoveralls

React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts. Uses a fork ofhotkeys.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.

Example

Install

npm i -S react-hot-keys

Demo

Previewdemo.

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>)}}

API

keyName

Supported keys,shift,option,,alt,ctrl,control,command, .

Command()
Control
Option(alt)
Shift
Caps Lock
fn Function key isfn (not supported)
↩︎ return/enterspace space keys

onKeyDown

Callback function to be called when user pressed the target buttonsspace space keys

onKeyUp

Callback function to be called when user key uped the target buttons

allowRepeat

allowRepeat?: boolean;

allowRepeat to allow auto repeating key down

disabled

disabled?: boolean;

DisableonKeyDown andonKeyUp events. Default:undefined

filter

INPUTSELECTTEXTAREA default does not handle.filter to return to the true shortcut keys set to play a role, flase shortcut keys set up failure.

 <Hotkeys    keyName="shift+a,alt+s"+   filter={(event) => {+     return true;+   }}   onKeyDown={this.onKeyDown.bind(this)}   onKeyUp={this.onKeyUp.bind(this)} />

Contributors

As always, thanks to our amazing contributors!

Made withaction-contributors.

License

Licensed under the MIT License.

About

React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors9


[8]ページ先頭

©2009-2025 Movatter.jp