4

I'm trying to get hold of when the user presses the Escape key with my app open (so not necessarily with an input field focussed). So far, however, I'm stuck at intercepting keyboard events at all. This is what I'm currently trying:

drivers.DOM.select(':root')
.events('keypress')
// .filter(ev => ev.keyCode === 27)
.map(ev => true)

I've tried catching evens on body and html as well, but both to no avail...

Vincent
  • 4,876
  • 3
  • 44
  • 55

1 Answers1

4

Just make a one-liner keyboard driver:

Cycle.run(main, {
  DOM: makeDOMDriver(containerElement),
  Keypress: () => Rx.Observable.fromEvent(document, 'keypress'); // <=====
});

Check this example: https://github.com/cyclejs/examples/blob/master/animated-letters/src/main.js#L110

André Staltz
  • 13,304
  • 9
  • 48
  • 58
  • 1
    Makes sense, thanks! (Amazing how elegant Cycle can be, thank you very much for making it :) ) – Vincent Mar 27 '16 at 15:36