Open1

OpenCV のキーコード調査簡易コード

PINTOPINTO
#!/usr/bin/env python

import cv2
import numpy as np

WINDOW_NAME = 'key_bind_test'
cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_NORMAL)
cv2.imshow(WINDOW_NAME, np.zeros([100,100]))
while True:
    res = cv2.waitKey(1)
    if res != -1:
        print(f"You pressed {res} ({res:#x}), 2LSB: {res % 2**16} ({repr(chr(res%256)) if res%256 < 128 else '?'})")
        if res == 27:
            break