python实现字符输入实时读取

原理:通过opencv中的waitKey来实现

示例代码:

def key_control():
    while 1:
        cv2.imshow('tmp', np.zeros(shape=(100, 100, 3), dtype=np.uint8))
        key = cv2.waitKey(1)
        if key == ord('w'):
        	print("w")
        elif key == ord('s'):
        	print("s")
        elif key == ord('a'):
        	print("a")
        elif key == ord('d'):
        	print("d")
        elif key == ord(' '):
            break
    cv2.destroyAllWindows()
posted @ 2023-07-09 18:22  ihuahua1415  阅读(43)  评论(0)    收藏  举报
*/