cylon/examples/keyboard/keyboard.markdown

693 B

Keyboard

For this Cylon example, we're going to quickly demonstrate getting keyboard input.

First, let's import Cylon:

var Cylon = require('../..');

With that done, let's define our robot:

Cylon.robot({

It will have a single connection and device, both to the keyboard.

  connection: { name: 'keyboard', adaptor: 'keyboard' },
  device: { name: 'keyboard', driver: 'keyboard' },

When we tell this robot to work, it's going to listen to the 'a' key on the keyboard and let us know when it's been pressed.

  work: function(my) {
    my.keyboard.on('a', function(key) { console.log("A PRESSED!") });
  }

With that done, let's get started!

}).start();