在我的应用程序中,我添加了一项功能,可在按键时(在ESC上或在按下Pause / Break按钮时)将应用程序窗口最小化到系统托盘。因此,按下它们时,窗口会最小化。
有没有一种方法可以添加功能以在某些按键上恢复应用程序窗口(即使其他应用程序当前处于活动状态)?
例如,我按“暂停”,窗口最小化。我按暂停,应用程序窗口将恢复。
这是从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);
本示例向您展示如何创建全局快捷方式侦听器以及侦听事件的其他方法。这也向您展示了如何注销快捷方式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句