【问题标题】:App window restore on keypress按键时应用程序窗口恢复
【发布时间】:2014-11-03 13:19:12
【问题描述】:

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

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

例如,我按下 Pause,窗口就会最小化。我按暂停,应用程序窗口恢复。

【问题讨论】:

    标签: node-webkit


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 2011-09-12
      • 2014-06-30
      相关资源
      最近更新 更多