keyboard module for games that works in the terminal
Useful for testing and debugging core game logic outside the browser, e.g. because you have separate modules for game logic and rendering and you want to test gameplay alone in the terminal. Works well alongside crtrdg.js
games, but can be used just as well independently. Captures key presses from stdin
using keypress
and separates key down and key up events using lodash.debounce
.
npm install --save crtrdg-tty
initialize and log key down events
var TTY = require('crtrdg-tty')
var tty = TTY()
tty.on('keyDown', function (key) {
console.log(key)
})
to see a simple interactive demo call
npm start
inside this module, and press or hold keys to see events.
create the tty object
var TTY = require('crtrdg-tty')
var tty = TTY()
key down events
provides a key code for the key pressed from vkey
key up events
provides a key code for the key let up from vkey
object with currently pressed keys set to true, e.g.
tty.on('keyDown', function () {
console.log(tty.keysDown)
})
>> {<up>: true}