在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:react-hotkeys开源软件地址:https://gitee.com/jaywcjlove/react-hotkeys开源软件介绍:react-hotkeysReact 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. ExampleInstallsudo npm i -S react-hot-keys DemoPreview demo. import React, { Component } from 'react';import Hotkeys from 'react-hot-keys';export default class HotkeysDemo extends 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 ( <Hotkeys keyName="shift+a,alt+s" onKeyDown={this.onKeyDown.bind(this)} onKeyUp={this.onKeyUp.bind(this)} > <div style={{ padding: "50px" }}> {this.state.output} </div> </Hotkeys> ) }} APIkeyNameSupported keys
onKeyDownCallback function to be called when user pressed the target buttons onKeyUpCallback function to be called when user key uped the target buttons LicenseMIT |
请发表评论