A keyboard driver for cycle.js. View Demo
Install the package using node package manager
$ npm install cycle-keyboard@1.0.0-rtm.4
Import the driver in your cycle app
import { makeKeyboardDriver } from 'cycle-keyboard'
...
const drivers = {
...
keyboard: makeKeyboardDriver()
}
Subscribe to keyboard-related event streams on the driver
function main({ ..., keyboard }) {
const keyUp$ = keyboard.ups().map(ev => ev.displayKey + ' was pressed');
}
The driver provides the following xstream streams:
ups(key?: number|string)
, a stream of all keyup events emitted on the document, with an additionaldisplayKey
property, optionally filtered by a key code or a key namedowns(key?: number|string)
, a stream of all keydown events emitted on the document, with an additionaldisplayKey
property, optionally filtered by a key code or a key namepresses(key?: number|string)
, a stream of all keypress events emitted on the document, with additionaldisplayKey
anddisplayChar
properties, optionally filtered by a key code or a key nameshift$
, a stream of booleans indicating if the shift key is held down, andcapsLock$
, a stream of booleans indicating if the caps lock is on