Skip to content

Commit

Permalink
Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 7, 2018
1 parent 03cc06b commit 21aac4e
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 48 deletions.
79 changes: 60 additions & 19 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),安装如下:
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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');
});
```

Expand Down
65 changes: 50 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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 "*"
Expand Down Expand Up @@ -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
Expand Down
58 changes: 44 additions & 14 deletions website/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 "*"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21aac4e

Please sign in to comment.