2017-03-04 57 views
0

我正在使用nw.js来创建一个exe文件。我可以将其设置为全屏模式,但是如何使用退出键逃脱它?人们建议下面的代码,但我把这个文件放在哪个文件中?nw.js如何逃脱全屏

var gui = window.requireNode('nw.gui'); 
gui.App.registerGlobalHotKey(new gui.Shortcut({ 
    key: "Esc", 
    active: function() { 
    gui.Window.get().leaveFullscreen(); 
    }) 
})); 

回答

1

正式通过以下方式提出的文件中: http://docs.nwjs.io/en/latest/For%20Users/FAQ/

你需要注册一个全局热键:

nw.App.registerGlobalHotKey(new nw.Shortcut({ 
    key: "Escape", 
    active: function() { 
    // decide whether to leave fullscreen mode 
    // then ... 
    nw.Window.get().leaveFullscreen(); 
    } 
})); 

您可以在您的应用程序的开始把这个片段。

<!DOCTYPE html> 
<html> 
<head> 
    <script> 
nw.App.registerGlobalHotKey(new nw.Shortcut({ 
    key: "Escape", 
    active: function() { 
    // decide whether to leave fullscreen mode 
    // then ... 
    nw.Window.get().leaveFullscreen(); 
    } 
})); 
    </script> 
</head> 
<body> 
</body> 
</html> 
0

你可以用它来退出firescreen

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <script> 
 
    var gui = require('nw.gui'); 
 
    gui.App.registerGlobalHotKey(new nw.Shortcut({ 
 
    key: "Escape", 
 
    active: function() { 
 
    // decide whether to leave fullscreen mode 
 
    // then ... 
 
    nw.Window.get().leaveFullscreen(); 
 
    } 
 
    })); 
 
    </script> 
 
</head> 
 
<body> 
 
</body> 
 
</html>

而这种切换firescreen:

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    </head> 
 
    <body> 
 
    <script> 
 
\t var gui = require('nw.gui'); \t 
 
\t gui.App.registerGlobalHotKey(new gui.Shortcut({ 
 
\t key: "F11", 
 
\t active: function() { 
 
    // decide whether to leave fullscreen mode 
 
    // then ... 
 
    gui.Window.get().toggleFullscreen(); 
 
\t } 
 
\t })); 
 
    </script> 
 
    </body> 
 
</html>

0

你可以用它来退出全屏

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <script> 
 
    var gui = require('nw.gui'); 
 
    gui.App.registerGlobalHotKey(new nw.Shortcut({ 
 
    key: "Escape", 
 
    active: function() { 
 
    // decide whether to leave fullscreen mode 
 
    // then ... 
 
    gui.Window.get().leaveFullscreen(); 
 
    } 
 
    })); 
 
    </script> 
 
</head> 
 
<body> 
 
</body> 
 
</html>

而这种切换全屏:

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    </head> 
 
    <body> 
 
    <script> 
 
\t var gui = require('nw.gui'); \t 
 
\t gui.App.registerGlobalHotKey(new gui.Shortcut({ 
 
\t key: "F11", 
 
\t active: function() { 
 
    // decide whether to leave fullscreen mode 
 
    // then ... 
 
    gui.Window.get().toggleFullscreen(); 
 
\t } 
 
\t })); 
 
    </script> 
 
    </body> 
 
</html>