简体   繁体   中英

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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