From 92f7899c60e3b9234c44ba71fa407be9029ae8fb Mon Sep 17 00:00:00 2001 From: GoooIce Date: Thu, 10 Sep 2015 22:29:22 +0800 Subject: [PATCH 1/2] Add api\global-shortcut.md Add api\global-shortcut.md --- .../zh-CN/api/global-shortcut.md | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 docs-translations/zh-CN/api/global-shortcut.md diff --git a/docs-translations/zh-CN/api/global-shortcut.md b/docs-translations/zh-CN/api/global-shortcut.md new file mode 100644 index 000000000000..ff0b28832a10 --- /dev/null +++ b/docs-translations/zh-CN/api/global-shortcut.md @@ -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()` + +注销本应用注册的所有全局快捷键. From ff67fae9ef8c53677bc36160e6a9b146c5f55178 Mon Sep 17 00:00:00 2001 From: GoooIce Date: Fri, 11 Sep 2015 17:27:20 +0800 Subject: [PATCH 2/2] Add api\accelerator.md Add api\accelerator.md --- docs-translations/zh-CN/api/accelerator.md | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 docs-translations/zh-CN/api/accelerator.md diff --git a/docs-translations/zh-CN/api/accelerator.md b/docs-translations/zh-CN/api/accelerator.md new file mode 100644 index 000000000000..8858d18e856e --- /dev/null +++ b/docs-translations/zh-CN/api/accelerator.md @@ -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`