在我的应用程序中,我添加了一个功能,可以在按键上将应用程序窗口最小化到系统托盘(在ESC或按下暂停/中断按钮时).所以当按下它们时,窗口会变得最小化.
有没有办法在某些按键上添加恢复应用程序窗口的功能(即使其他应用程序当前处于活动状态)?
例如,我按Pause键,窗口最小化.我按暂停键,应用程序窗口恢复.
这是从node-webkit wiki中提取的解决方案:
// Load native UI library.
var gui = require('nw.gui');
var option = {
key: "Ctrl+Shift+A",
active: function() {
console.log("Global desktop keyboard shortcut: " + this.key + " active.");
},
failed: function(msg) {
// :(, fail to register the |key| or couldn't parse the |key|.
console.log(msg);
}
};
// Create a shortcut with |option|.
var shortcut = new gui.Shortcut(option);
// Register global desktop shortcut, which can work without focus.
gui.App.registerGlobalHotKey(shortcut);
// If register |shortcut| successfully and user struck "Ctrl+Shift+A", |shortcut|
// will get an "active" event.
// You can also add listener to shortcut's active and failed event.
shortcut.on('active', function() {
console.log("Global desktop keyboard shortcut: " + this.key + " active.");
});
shortcut.on('failed', function(msg) {
console.log(msg);
});
// Unregister the global desktop shortcut.
gui.App.unregisterGlobalHotKey(shortcut);
Run Code Online (Sandbox Code Playgroud)
此示例显示如何创建全局快捷方式侦听器以及侦听事件的不同方法.这也向您展示了如何取消注册快捷方式.
| 归档时间: |
|
| 查看次数: |
654 次 |
| 最近记录: |