Update docs.

pull/23/head
jaywcjlove 7 years ago
parent 03cc06b6cb
commit 21aac4eda8

@ -28,6 +28,32 @@ $ npm run build # 编译
$ npm run watch # 开发模式
```
```js
import hotkeys from 'hotkeys-js';
hotkeys('f5', function(event, handler){
// Prevent the default refresh event under WIDNOWS system
event.preventDefault()
alert('you pressed F5!')
});
```
或者在您的HTML中手动下载并引入** hotkeys.js **
```html
<script type="text/javascript" src="hotkeys.js"></script>
<script type="text/javascript">
hotkeys('ctrl+a,ctrl+b,r,f', function(event,handler) {
switch(handler.key){
case "ctrl+a":alert('you pressed ctrl+a!');break;
case "ctrl+b":alert('you pressed ctrl+b!');break;
case "r":alert('you pressed r!');break;
case "f":alert('you pressed f!');break;
}
});
<script>
```
## React中使用
[react-hotkeys](https://github.com/jaywcjlove/react-hotkeys),安装如下:
@ -92,9 +118,35 @@ hotkeys('shift+a,alt+d, w', function(e){
});
```
## 支持的键
`⇧`, `shift`, `option`, `⌥`, `alt`, `ctrl`, `control`, `command`, `⌘`
`⌘` Command()
`⌃` Control
`⌥` Option(alt)
`⇧` Shift
`⇪` Caps Lock(大写)
~~`fn` 功能键就是fn(不支持)~~
`↩︎` return/enter
`space` 空格键
## 修饰键判断
可以对下面的修饰键判断 `shift` `alt` `option` `ctrl` `control` `command`,特别注意`+`和`=`键值相同,组合键设置`⌘+=`
```js
hotkeys('shift+a,alt+d, w', function(e){
console.log('干点活儿',e);
if(hotkeys.shift) console.log('大哥你摁下了 shift 键!');
if(hotkeys.ctrl) console.log('大哥你摁下了 ctrl 键!');
if(hotkeys.alt) console.log('大哥你摁下了 alt 键!');
});
```
## 定义快捷键
> `hotkeys([keys:<String>], [option:[string|object|function]], [callback:<function>])`
```js
// 定义 F5 快捷键
hotkeys('f5', function(event,handler){
@ -141,28 +193,17 @@ hotkeys('*','wcj', function(e){
});
```
## 支持的键
#### option
`⇧`, `shift`, `option`, `⌥`, `alt`, `ctrl`, `control`, `command`, `⌘`
`⌘` Command()
`⌃` Control
`⌥` Option(alt)
`⇧` Shift
`⇪` Caps Lock(大写)
~~`fn` 功能键就是fn(不支持)~~
`↩︎` return/enter
`space` 空格键
## 修饰键判断
可以对下面的修饰键判断 `shift` `alt` `option` `ctrl` `control` `command`,特别注意`+`和`=`键值相同,组合键设置`⌘+=`
- scope<String>
- element<HTMLElement>
```js
hotkeys('shift+a,alt+d, w', function(e){
console.log('干点活儿',e);
if(hotkeys.shift) console.log('大哥你摁下了 shift 键!');
if(hotkeys.ctrl) console.log('大哥你摁下了 ctrl 键!');
if(hotkeys.alt) console.log('大哥你摁下了 alt 键!');
hotkeys('o, enter', {
scope: 'wcj',
element: document.getElementById('warpper'),
}, function(){
console.log('do something else');
});
```

@ -22,12 +22,28 @@ $ npm install hotkeys-js --save
```js
import hotkeys from 'hotkeys-js';
hotkeys('f5', function(event, handler){
// Prevent the default refresh event under WIDNOWS system
event.preventDefault()
alert('you pressed F5!')
});
```
Or manually download and link **hotkeys.js** in your HTML:
```html
<script type="text/javascript" src="hotkeys.js"></script>
<script type="text/javascript">
hotkeys('ctrl+a,ctrl+b,r,f', function(event,handler) {
switch(handler.key){
case "ctrl+a":alert('you pressed ctrl+a!');break;
case "ctrl+b":alert('you pressed ctrl+b!');break;
case "r":alert('you pressed r!');break;
case "f":alert('you pressed f!');break;
}
});
<script>
```
### Used in React
@ -82,10 +98,29 @@ Firefox
Chrome
```
## Supported Keys
HotKeys understands the following modifiers: `⇧`, `shift`, `option`, `⌥`, `alt`, `ctrl`, `control`, `command`, and `⌘`.
The following special keys can be used for shortcuts: backspace, tab, clear, enter, return, esc, escape, space, up, down, left, right, home, end, pageup, pagedown, del, delete and f1 through f19.
`⌘` Command()
`⌃` Control
`⌥` Option(alt)
`⇧` Shift
`⇪` Caps Lock(Capital)
~~`fn` Does not support fn~~
`↩︎` return/Enter space
## Defining Shortcuts
One global method is exposed, key which defines shortcuts when called directly.
```
hotkeys([keys:<String>], [option:[string|object|function]], [callback:<function>])
```
```js
hotkeys('f5', function(event, handler){
// Prevent the default refresh event under WIDNOWS system
@ -102,7 +137,7 @@ hotkeys('a', function(event,handler){
alert('you pressed a!')
});
hotkeys('ctrl+a,ctrl+b,r,f', function(event,handler){
hotkeys('ctrl+a,ctrl+b,r,f', function(event,handler) {
switch(handler.key){
case "ctrl+a":alert('you pressed ctrl+a!');break;
case "ctrl+b":alert('you pressed ctrl+b!');break;
@ -116,6 +151,20 @@ hotkeys('*','wcj', function(e){
});
```
#### option
- scope<String>
- element<HTMLElement>
```js
hotkeys('o, enter', {
scope: 'wcj',
element: document.getElementById('warpper'),
}, function(){
console.log('do something else');
});
```
## API REFERENCE
Asterisk "*"
@ -238,20 +287,6 @@ hotkeys()
// @ VM2165:883InjectedScript._evaluateAndWrap
// @ VM2165:816InjectedScript.evaluate @ VM2165:682
```
## Supported Keys
HotKeys understands the following modifiers: `⇧`, `shift`, `option`, `⌥`, `alt`, `ctrl`, `control`, `command`, and `⌘`.
The following special keys can be used for shortcuts: backspace, tab, clear, enter, return, esc, escape, space, up, down, left, right, home, end, pageup, pagedown, del, delete and f1 through f19.
`⌘` Command()
`⌃` Control
`⌥` Option(alt)
`⇧` Shift
`⇪` Caps Lock(Capital)
~~`fn` Does not support fn~~
`↩︎` return/Enter space
## Development

@ -21,12 +21,28 @@ $ npm install hotkeys-js --save
```js
import hotkeys from 'hotkeys-js';
hotkeys('f5', function(event, handler){
// Prevent the default refresh event under WIDNOWS system
event.preventDefault()
alert('you pressed F5!')
});
```
Or manually download and link **hotkeys.js** in your HTML:
```html
<script type="text/javascript" src="hotkeys.js"></script>
<script type="text/javascript">
hotkeys('ctrl+a,ctrl+b,r,f', function(event,handler) {
switch(handler.key){
case "ctrl+a":alert('you pressed ctrl+a!');break;
case "ctrl+b":alert('you pressed ctrl+b!');break;
case "r":alert('you pressed r!');break;
case "f":alert('you pressed f!');break;
}
});
<script>
```
### Used in React
@ -77,6 +93,20 @@ Firefox
Chrome
```
## Supported Keys
HotKeys understands the following modifiers: `⇧`, `shift`, `option`, `⌥`, `alt`, `ctrl`, `control`, `command`, and `⌘`.
The following special keys can be used for shortcuts: backspace, tab, clear, enter, return, esc, escape, space, up, down, left, right, home, end, pageup, pagedown, del, delete and f1 through f19.
`⌘` Command()
`⌃` Control
`⌥` Option(alt)
`⇧` Shift
`⇪` Caps Lock(Capital)
~~`fn` Does not support fn~~
`↩︎` return/Enter space
## Defining Shortcuts
One global method is exposed, key which defines shortcuts when called directly.
@ -111,6 +141,20 @@ hotkeys('*','wcj', function(e){
});
```
#### option
- scope<String>
- element<HTMLElement>
```js
hotkeys('o, enter', {
scope: 'wcj',
element: document.getElementById('warpper'),
}, function(){
console.log('do something else');
});
```
## API REFERENCE
Asterisk "*"
@ -233,20 +277,6 @@ hotkeys()
// @ VM2165:883InjectedScript._evaluateAndWrap
// @ VM2165:816InjectedScript.evaluate @ VM2165:682
```
## Supported Keys
HotKeys understands the following modifiers: `⇧`, `shift`, `option`, `⌥`, `alt`, `ctrl`, `control`, `command`, and `⌘`.
The following special keys can be used for shortcuts: backspace, tab, clear, enter, return, esc, escape, space, up, down, left, right, home, end, pageup, pagedown, del, delete and f1 through f19.
`⌘` Command()
`⌃` Control
`⌥` Option(alt)
`⇧` Shift
`⇪` Caps Lock(Capital)
~~`fn` Does not support fn~~
`↩︎` return/Enter space
## Development

Loading…
Cancel
Save