kbd

0.1.0 • Public • Published

kbd

kbd module provides various utilities for keyboard. I wanted to have a node equivalent for printf, scanf, puts, gets for my students to whom I teach programming with node. kdb provides these functions in both synchrone and asynchrone mode. kdb also gives the opportunity to set/unset echo, set unset canonical mode.

This version is completely rewritten with "nan" (Native Abstraction for Node.js). Sorry for any bad english ;-)

var kbd = require('kbd');
// synchronously reads one line from keyboard
 
var line = kbd.getLineSync();
// asynchronously reads one line from keyboard
 
kbd.getLine(function (error, line) {
    // line variable contains keyboard entered line
};
// synchronously reads one key from keyboard in non canonical mode without echo
 
kbd.setEcho(false);             // no echo mode
kbd.setCanonical(false);        // non canonical mode
var char = kbd.getKeySync();
kbd.setEcho(true);              // reestablish echo mode
kbd.setCanonical(true);         // reestablish canonical mode
// asynchronously reads key from keyboard in non canonical mode without echo
 
kbd.setEcho(false);             // no echo mode
kbd.setCanonical(false);        // non canonical mode
kbd.getKey(function (error, key) {
    // key variable contains pressed key
    // dont forget to reset echo and canonical mode before the end of script
    // if you forgot, type shell 'reset' command
    kbd.setEcho(true);              // reestablish echo mode
    kbd.setCanonical(true);         // reestablish canonical mode
});

Package Sidebar

Install

npm i kbd

Weekly Downloads

0

Version

0.1.0

License

BSD

Last publish

Collaborators

  • pthire