按键上的应用程序窗口恢复

时间:2014-11-03 13:19:13

标签: node-webkit

在我的应用程序中,我添加了一项功能,可以在按键上将应用程序窗口最小化到系统托盘(按ESC键或暂停/中断按钮按下)。因此,当按下它们时,窗口会被最小化。

有没有办法在某些按键上添加恢复应用程序窗口的功能(即使其他应用程序当前处于活动状态)?

例如,我按暂停,窗口最小化。我按暂停,即可恢复应用窗口。

1 个答案:

答案 0 :(得分:5)

以下是从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);

此示例显示如何创建全局快捷方式侦听器以及侦听事件的不同方式。这也向您展示了如何取消注册快捷方式。