2014-02-21 06:08:26 +08:00
|
|
|
# Keyboard
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
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:
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
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' }
|
|
|
|
},
|
2014-03-27 08:06:26 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2014-06-07 06:24:13 +08:00
|
|
|
work: function(my) {
|
2014-11-26 06:39:24 +08:00
|
|
|
my.keyboard.on('a', function(key) {
|
|
|
|
console.log("a pressed!")
|
|
|
|
});
|
2014-03-27 08:06:26 +08:00
|
|
|
}
|
2014-02-21 06:08:26 +08:00
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
With that done, let's get started!
|
2014-02-21 06:08:26 +08:00
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
}).start();
|