发布时间:2019-09-10 08:45:23编辑:auto阅读(2069)
#!/usr/bin/env python 
# -*- coding: utf-8 -*-
import  os  
import  sys
import  tty, termios
import time    
if __name__ == '__main__':
	print "Reading form keybord"
	print """   i
j  k  l
   m"""
	print 'press Q to quit'
	while True:
		fd=sys.stdin.fileno()
		old_settings=termios.tcgetattr(fd)
		#old_settings[3]= old_settings[3] & ~termios.ICANON & ~termios.ECHO  
		try:
			tty.setraw(fd)
			ch=sys.stdin.read(1)
		finally:
			termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)  
			#print 'error'
		if ch=='i':
			print 'move forward'
		elif ch=='m':
			print 'move back'
		elif ch=='j':
			print "turn left!"
		elif ch=='l':
			print "turn right!"
		elif ch=='u':
			print "turn right!"
		elif ch=='o':
			print "turn right!"
		elif ch=='k':
			print "stop motor!"
		elif ch=='q':
			print "shutdown!"
			break
		elif ord(ch)==0x3:
			#这个是ctrl c
			print "shutdown"
			break
		print "Reading form keybord"
		print """   i
j  k  l
   m"""
		print 'press Q or ctrl+c to quit'
		#rate.sleep() 
 
上一篇: 基于python的protobuf简介及
下一篇: Python - SocketIO 请求
 51196
 50616
 41238
 38053
 32516
 29423
 28283
 23141
 23098
 21436
 1492°
 2205°
 1830°
 1759°
 2067°
 1817°
 2501°
 4200°
 4062°
 2899°