Python 键盘和鼠标事件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #!/usr/bin/env python # !_*_ coding:utf-8 _*_ import os import cv2 as cv import numpy as np import sys def keyboard_demo(): continue_flag = True single_flag = False while True : while continue_flag: mouse_demo() for filename in dir_list: path = os.path.join( 'imgs' , filename) # print(path) image = cv.imread(path) cv.imshow( "Contuinue" , image) key = cv.waitKey( 500 ) if key = = ord ( 's' ): continue_flag = False single_flag = True cv.destroyAllWindows() break if key & 0xFF = = 27 : sys.exit() while single_flag: for filename in dir_list: path = os.path.join( 'imgs' , filename) # print(path) image = cv.imread(path) cv.imshow( "Single" , image) key = cv.waitKey( 0 ) if key = = ord ( 'c' ): continue_flag = True single_flag = False cv.destroyAllWindows() break if key & 0xFF = = 27 : sys.exit() def tempstop(event, x, y, flags, para): if event = = cv.EVENT_LBUTTONDOWN: print ( "stop" ) cv.waitKey( 0 ) elif event = = cv.EVENT_MOUSEMOVE: print ( "Mouse move" ) cv.waitKey( 1000 ) def mouse_demo(): cv.namedWindow( "Contuinue" , cv.WINDOW_AUTOSIZE) cv.setMouseCallback( "Contuinue" , tempstop) if __name__ = = '__main__' : dir_list = os.listdir( './imgs' ) # print(dir_list) # mouse_demo() keyboard_demo() |
照片连续显示,
鼠标移至图像上面 ,图像暂停
按 “c” ,图像连续显示,按 “s”,图像单个显示
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步