如何在linux中使用python检测当前鼠标光标类型?

问题描述

我想要做的是使用 python 找出当前在 Linux 中活动的游标类型(即指针、普通、插入)。

我发现一篇文章提到对于使用 win32gui 的 Windows:The way to detect the current mouse cursor type from bash or python

win32gui 是特定于 Windows 的,这个库在 Linux 中不起作用。还有其他解决方案吗?

解决方法

更新:我提出了三个解决方案,但它们相当费力且资源密集。而且我还没有对它们进行测试,所以我不知道有什么障碍。因此,在这一点上,我仍然希望能够解决这个问题。

(1) 您可以使用 pyautogui 找出鼠标指针的位置,然后拍摄指针的快照。然后,您可以将此图像与光标的测试图像进​​行比较,并使用 OpenCV 计算这两个图像的相似程度。

(2) 通过 Wine 之类的服务运行 win32gui 并将游标数据发送到 linux 应用程序。

(3) 使用python的ctype模块调用XFixes C library's XFixesGetCursorImage(display) function.

,

Use this library PyXCursor to get the image of cursor/mouse-pointer for an arbitrary application window in Linux - in Python using ctypes