-
Notifications
You must be signed in to change notification settings - Fork 5
/
keyboard.py
79 lines (58 loc) · 1.37 KB
/
keyboard.py
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
75
76
77
78
79
import curses
from motion import movement
import time
m = movement.Movement()
thrust = 200
def motion(key):
global thrust
if key == 'w':
m.forward(thrust)
elif key == 's':
m.backward(thrust)
elif key == 'a':
m.left(thrust)
elif key == 'd':
m.right(thrust)
elif key == 'i':
m.up(thrust)
elif key == 'o':
m.down(thrust)
elif key == 'q':
print("Quit")
m.hold()
time.sleep(1)
exit()
elif key == 'h':
m.hold()
elif key == 'm':
m.tilt_forward(thrust)
elif key == 'n':
m.tilt_backward(thrust)
elif key == '+':
thrust += 10
if thrust >= 200:
thrust = 200
elif key == '-':
thrust -= 10
if thrust <= 0:
thrust = 0
else:
print('None')
m.hold()
def main(stdscr):
print('In the main loop.')
stdscr.nodelay(True)
stdscr.clear()
while True:
stdscr.addstr('Thrust = ' + str(thrust) + '\n')
c = stdscr.getch()
curses.flushinp()
if c == -1:
stdscr.clear()
m.hold()
else:
stdscr.clear()
stdscr.addstr('Pressed ' + chr(c) + '\n')
motion(chr(c))
time.sleep(0.06)
curses.wrapper(main)