Merge pull request #2762 from GoooIce/master

Add docs-translations\api\ global-shortcut.md and accelerator.md for zh-CN
This commit is contained in:
Cheng Zhao 2015-09-11 21:09:07 +08:00
commit 989799633d
2 changed files with 106 additions and 0 deletions

View file

@ -0,0 +1,46 @@
# Accelerator
An accelerator is a string that represents a keyboard shortcut. It can contain
multiple modifiers and key codes, combined by the `+` character.
Examples:
* `Command+A`
* `Ctrl+Shift+Z`
## Platform notice
On Linux and Windows, the `Command` key does not have any effect so
use `CommandOrControl` which represents `Command` on OS X and `Control` on
Linux and Windows to define some accelerators.
The `Super` key is mapped to the `Windows` key on Windows and Linux and
`Cmd` on OS X.
## Available modifiers
* `Command` (or `Cmd` for short)
* `Control` (or `Ctrl` for short)
* `CommandOrControl` (or `CmdOrCtrl` for short)
* `Alt`
* `Shift`
* `Super`
## Available key codes
* `0` to `9`
* `A` to `Z`
* `F1` to `F24`
* Punctuations like `~`, `!`, `@`, `#`, `$`, etc.
* `Plus`
* `Space`
* `Backspace`
* `Delete`
* `Insert`
* `Return` (or `Enter` as alias)
* `Up`, `Down`, `Left` and `Right`
* `Home` and `End`
* `PageUp` and `PageDown`
* `Escape` (or `Esc` for short)
* `VolumeUp`, `VolumeDown` and `VolumeMute`
* `MediaNextTrack`, `MediaPreviousTrack`, `MediaStop` and `MediaPlayPause`

View file

@ -0,0 +1,60 @@
# global-shortcut
`global-shortcut` 模块可以便捷的为您设置(注册/注销)各种自定义操作的快捷键.
**Note**: 使用此模块注册的快捷键是系统全局的(QQ截图那种), 不要在应用模块(app module)响应 `ready`
消息前使用此模块(注册快捷键).
```javascript
var app = require('app');
var globalShortcut = require('global-shortcut');
app.on('ready', function() {
// Register a 'ctrl+x' shortcut listener.
var ret = globalShortcut.register('ctrl+x', function() {
console.log('ctrl+x is pressed');
})
if (!ret) {
console.log('registration failed');
}
// Check whether a shortcut is registered.
console.log(globalShortcut.isRegistered('ctrl+x'));
});
app.on('will-quit', function() {
// Unregister a shortcut.
globalShortcut.unregister('ctrl+x');
// Unregister all shortcuts.
globalShortcut.unregisterAll();
});
```
## Methods
`global-shortcut` 模块包含以下函数:
### `globalShortcut.register(accelerator, callback)`
* `accelerator` [Accelerator](accelerator.md)
* `callback` Function
注册 `accelerator` 快捷键. 当用户按下注册的快捷键时将会调用 `callback` 函数.
### `globalShortcut.isRegistered(accelerator)`
* `accelerator` [Accelerator](accelerator.md)
查询 `accelerator` 快捷键是否已经被注册过了,将会返回 `true`(已被注册) 或 `false`(未注册).
### `globalShortcut.unregister(accelerator)`
* `accelerator` [Accelerator](accelerator.md)
注销全局快捷键 `accelerator`.
### `globalShortcut.unregisterAll()`
注销本应用注册的所有全局快捷键.