简体   繁体   English

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

[英]How to detect the current mouse cursor type using python in linux?

What I'd like to do is find out the type of cursor (ie. pointer, normal, insert) currently active in Linux using python.我想做的是使用 python 找出当前在 Linux 中活动的 cursor 的类型(即指针,正常,插入)。

I've found one post mentioning that for windows using win32gui : The way to detect the current mouse cursor type from bash or python I've found one post mentioning that for windows using win32gui : The way to detect the current mouse cursor type from bash or python

win32gui is Windows-specific and this library will not work in Linux. win32gui是特定于 Windows 的,这个库在 Linux 中不起作用。 Any other solutions?还有其他解决方案吗?

Update: I have come up with three solutions, but they are rather effort and resource-intensive.更新:我提出了三个解决方案,但它们相当耗费精力和资源。 And I haven't tested them out, so I don't know about any roadblocks.而且我还没有对它们进行测试,所以我不知道有任何障碍。 So at this point, I would still appreciate alternative solutions to this problem.所以在这一点上,我仍然会欣赏这个问题的替代解决方案。

(1) You could find out the location of the mouse pointer using pyautogui and then take a snapshot of the pointer. (1) 您可以使用pyautogui找出鼠标指针的位置,然后对指针进行快照。 Then you could compare this image with a test image of a cursor and calculate how similar both images look like using OpenCV .然后,您可以将此图像与 cursor 的测试图像进行比较,并使用OpenCV计算这两个图像的相似程度。

(2) Run win32gui via Wine like service and send cursor data to linux application. (2) 通过Wine like 服务运行 win32gui 并将 cursor 数据发送到 linux 应用程序。

(3) Use python's ctype module to call XFixes C library's X FixesGetCursorImage(display) function. (3) 使用python的ctype模块调用XFixes C库的X FixesGetCursorImage(display) function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM