-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypress2.js
74 lines (63 loc) · 1.46 KB
/
keypress2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var arDrone = require('ar-drone');
var client = arDrone.createClient();
const readline = require('readline');
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str, key) => {
// key.name='k';
if (key.name === 'w') {
client.takeoff();
console.log('drone is taking off.....');
}
else if (key.name === 's') {
client.land();
console.log('drone is landing....');
}
else if (key.name === 'a') {
client.front(0.2);
client
.after(2000, function() {
this.stop(0.2);
})
console.log('drone is forwarding....');
}
else if (key.name === 'd') {
client.back(0.2);
client
.after(2000, function() {
this.stop(0.2);
})
console.log('drone is reversing....');
}
else if (key.name === 'q') {
client.clockwise(0.2);
client
.after(2000, function() {
this.stop(0.2);
})
console.log('drone is rotating....');
}
else if (key.name === 'k') {
client.up(0.2);
client
.after(2000, function() {
this.stop(0.2);
})
console.log('drone is upwards....');
} else if (key.name === 'l') {
client.down(0.2);
client
.after(2000, function() {
this.stop(0.2);
})
console.log('drone is downwards....');
}
else {
console.log(`You pressed the "${str}" key`);
console.log('BM')
console.log();
console.log(key);
console.log();
}
});
console.log('Press any key...');