简体   繁体   English

原子外壳中的关键事件

[英]key events in atom shell

Let's say I want to have a key event only on my compiled application with atom shell. 假设我只想在带有原子外壳的已编译应用程序上有一个键事件。

var app = require('app');
var BrowserWindow = require('browser-window');
require('crash-reporter').start();

app.on('ready', function() {
  win = new BrowserWindow({ fullscreen: true, frame: false });
  win.hide();
  win.loadUrl("http://localhost:3000");

  win.webContents.on('did-finish-load', function() {
    win.show();
    win.focus();
  });

  process.on('uncaughtException', app.quit);
});

How could I bind a keyboard event on the web browser? 如何在网络浏览器上绑定键盘事件? Eg, 例如,

win.on('keypress', 'left-arrow', function() {
  win.webContents.goBack();
});

Also, apparently left arrow fires on key down, not key press. 而且,显然按下左键会触发,而不是按下键。 Credit: Detecting arrow key presses in JavaScript 信用: 检测JavaScript中的箭头键按下

I'm just learning about atom-shell, but couldn't you catch the keypress inside your UI (I think it's called the rendererer process), like you would in a typical web page, then use the remote() API to call back to the renderer process and do whatever logic you wanted? 我只是在学习atomic-shell,但不能像在典型的网页中一样在UI中捕获按键(我认为这称为渲染器进程),然后使用remote()API进行回调渲染器过程,并执行您想要的任何逻辑?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM