How to capture mouse movement for the whole window in opencv python?

心不动则不痛 提交于 2020-04-16 08:33:08

问题


I know and have seen tons of documentations explaining about how to capture mouse movement within a given window using mouseclick events in opencv. What I want to know is that if is there a way to capture mouse movements (x,y co-ordinates) for the entire screen of my system.

Any link, documentation or code snippet will be really helpful to proceed me with the same.


回答1:


Depending on your OS, you can do that with pyautogui like this:

#!/usr/bin/env python3

import time
import pyautogui

for i in range(10):
    x, y = pyautogui.position()
    print(f'Mouse position: x={x}, y={y}')
    time.sleep(1)


来源:https://stackoverflow.com/questions/60882907/how-to-capture-mouse-movement-for-the-whole-window-in-opencv-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!