Skip to content
Snippets Groups Projects
Commit cb384acd authored by Zhaoliang Zheng's avatar Zhaoliang Zheng
Browse files

fixed the key input bug

parent b72f8495
No related merge requests found
......@@ -13,35 +13,71 @@ def manual_control():
def variables_change():
print("variables_change function")
def init():
pygame.init()
win= pygame.display.set_mode((400,400))
def keyboard_stop(flag_s,print_count_s):
if get_key('q'):
flag_s = 0
print_count_s = 1
return flag_s,print_count_s
def get_key(keyname):
ans = False
for eve in pygame.event.get(): pass
keyInput = pygame.key.get_pressed()
myKey = getattr(pygame,'K_{}'.format(keyname))
# K_{LEFT}
if keyInput[myKey]:
ans = True
pygame.display.update()
return ans
if __name__ == '__main__':
flag = 0
print_count = 1
init()
while True:
key = cv2.waitKey(5)
if key == ord('a'):
if get_key('a'):
flag = 1
while (flag == 1):
auto_control()
flag, print_count = keyboard_stop()
elif key == ord('s'):
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
if not ret:
continue
cv2.imshow("image", frame)
flag, print_count = keyboard_stop(flag,print_count)
if flag == 0:
cap.release()
cv2.destroyAllWindows()
elif get_key('s'):
stop_all()
print("stop all motors")
elif key == ord('c'):
elif get_key('m'):
flag = 2
while (flag == 2):
manual_control()
flag, print_count = keyboard_stop()
flag, print_count = keyboard_stop(flag,print_count)
elif key == ord('v'):
elif get_key('v'):
flag = 3
while (flag == 3):
variables_change()
flag, print_count = keyboard_stop()
flag, print_count = keyboard_stop(flag,print_count)
elif get_key('k'):
break
if print_count is not 0:
print("No subsystem is running")
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment