按下按键即可恢复应用程序窗口 [英] App window restore on keypress

查看:108
本文介绍了按下按键即可恢复应用程序窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my app I have added a functionality to minimize app window to system tray on keypress (on ESC or Pause/Break buttons press). So when pressing them the window get minimized.

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

Is there a way to add functionality to restore app window on certain keypress (even if other application will be currently active)?

例如,我按下暂停,窗口最小化.我按暂停,应用窗口恢复.

For example I press Pause and the window is minimized. I press Pause and the app window is restored.

推荐答案

以下是从node-webkit Wiki中提取的解决方案:

Here is the solution extracted from 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);

此示例向您展示如何创建全局快捷方式侦听器以及侦听事件的其他方法.这也向您展示了如何注销快捷方式.

This example show you how to create a global shortcut listener and the different way to listen the event. This also show you how to unregister the shortcut.

这篇关于按下按键即可恢复应用程序窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆