2

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();
});
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
corvid
  • 10,733
  • 11
  • 61
  • 130

1 Answers1

1

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?

Community
  • 1
  • 1
Jonas
  • 4,454
  • 3
  • 37
  • 45