nw.js 如何退出全屏

nw.js how to escape fullscreen

我正在使用 nw.js 制作一个 exe 文件。我可以将它设置为全屏模式,但如何使用转义键将其转义?人们建议使用以下代码,但我应该将其放入哪个文件?

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

官方文档中建议采用以下方式: 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>

你可以用它来退出 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>

这是切换火屏的方法:

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

您可以使用它退出全屏

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