cylon/examples/keyboard/keyboard.markdown

36 lines
734 B
Markdown
Raw Permalink Normal View History

2014-02-21 06:08:26 +08:00
# Keyboard
For this Cylon example, we're going to quickly demonstrate getting keyboard
input.
2014-02-21 06:08:26 +08:00
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.
2014-11-26 08:01:31 +08:00
connections: {
keyboard: { adaptor: 'keyboard' }
},
devices: {
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) {
2014-11-26 06:39:24 +08:00
my.keyboard.on('a', function(key) {
console.log("a pressed!")
});
}
2014-02-21 06:08:26 +08:00
With that done, let's get started!
2014-02-21 06:08:26 +08:00
}).start();