如何在opencv python中捕获整个窗口的鼠标移动? [英] How to capture mouse movement for the whole window in opencv python?

查看:425
本文介绍了如何在opencv python中捕获整个窗口的鼠标移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道并且看过无数的文档,它们解释了如何使用opencv中的mouseclick事件捕获给定窗口内的鼠标移动.我想知道的是,是否有一种方法可以捕获整个系统屏幕上的鼠标移动(x,y坐标).

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.

推荐答案

根据您的操作系统,可以使用pyautogui来做到这一点,如下所示:

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)

这篇关于如何在opencv python中捕获整个窗口的鼠标移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆