show | version | enable_checker |
---|---|---|
step |
1.0 |
true |
- 上次研究了鼠标的各种互动效果
- 键盘可以有什么互动效果吗??🤔
import cv2
import numpy as np
canvas = np.zeros((300,300,3),np.uint8)
cv2.imshow("win",canvas)
while True:
key = cv2.waitKey(0)
cv2.putText(canvas,chr(key),(30,80),cv2.FONT_HERSHEY_TRIPLEX,2,(0,0,255),5)
cv2.imshow("win",canvas)
- 如果按下F1
- 需要将输出的字符序号限制在ascii范围(0-127)
- 如果按F1
- 就退出
- 如果在ascii范围内
- 就输出
import cv2
import numpy as np
canvas = np.zeros((300,300,3),np.uint8)
cv2.imshow("win",canvas)
while True:
key = cv2.waitKey(0)
if key == ord("q"):
break
if 0 < key < 127:
cv2.putText(canvas,chr(key),(30,80),cv2.FONT_HERSHEY_TRIPLEX,2,(0,0,255),5)
cv2.imshow("win",canvas)
- 键盘输入字符
- 可以将字形输出到终端频幕上
- 可以输入一个字符平移一下吗?
import cv2
import numpy as np
canvas = np.zeros((300,300,3),np.uint8)
x = 80
dx = 0
cv2.imshow("win",canvas)
while True:
key = cv2.waitKey(0)
if key == ord("q"):
break
if 0 < key < 127:
cv2.putText(canvas,chr(key),(x + dx,30),cv2.FONT_HERSHEY_TRIPLEX,2,(0,0,255),5)
cv2.imshow("win",canvas)
dx = dx + 40
- 效果
- 如果超过5个字符 可以添加还行特效吗?
import cv2
import numpy as np
canvas = np.zeros((300,300,3),np.uint8)
x = 40
dx = 40
y = 60
dy = 40
cv2.imshow("win",canvas)
while True:
key = cv2.waitKey(0)
print(key)
if key == 13:
x = 40
y = y + dy
continue
if key == ord("q"):
break
if 0 < key < 127:
cv2.putText(canvas,chr(key),(x, y),cv2.FONT_HERSHEY_TRIPLEX,2,(0,0,255),5)
cv2.imshow("win",canvas)
x = x + dx
- 执行效果
- 这次研究了键盘互动的效果
- 写字效果
- 感觉可以做一个打字练习器
- 下次玩点什么呢?🤔
- 下次再说👋