Python 检测鼠标光标是否被任何其他应用程序隐藏或可见

Python 检测鼠标光标是否被任何其他应用程序隐藏或可见,python,c,windows,mouse,Python,C,Windows,Mouse,我想检测鼠标当前是否隐藏,这通常是由Windows上的3D应用程序完成的。这似乎比听起来更棘手,因为我找不到任何方法来做到这一点 最好我想用Python来做这件事,但如果不可能的话,我可以求助于C语言。谢谢 该函数返回一个结构,该结构具有包含全局光标状态的标志字段。这能满足你的需要吗?我不熟悉Python,因此不知道是否可以从Python调用此函数。您需要调用此函数。这可以直接使用。或者,如果不希望安装外部Python库,可以使用直接从User32.dll访问函数 例如: import ctyp

我想检测鼠标当前是否隐藏,这通常是由Windows上的3D应用程序完成的。这似乎比听起来更棘手,因为我找不到任何方法来做到这一点

最好我想用Python来做这件事,但如果不可能的话,我可以求助于C语言。谢谢

该函数返回一个结构,该结构具有包含全局光标状态的
标志
字段。这能满足你的需要吗?我不熟悉Python,因此不知道是否可以从Python调用此函数。

您需要调用此函数。这可以直接使用。或者,如果不希望安装外部Python库,可以使用直接从User32.dll访问函数

例如:

import ctypes

# Argument structures
class POINT(ctypes.Structure):
    _fields_ = [('x', ctypes.c_int),
                ('y', ctypes.c_int)]

class CURSORINFO(ctypes.Structure):
    _fields_ = [('cbSize', ctypes.c_uint),
                ('flags', ctypes.c_uint),
                ('hCursor', ctypes.c_void_p),
                ('ptScreenPos', POINT)]

# Load function from user32.dll and set argument types
GetCursorInfo = ctypes.windll.user32.GetCursorInfo
GetCursorInfo.argtypes = [ctypes.POINTER(CURSORINFO)]

# Initialize the output structure
info = CURSORINFO()
info.cbSize = ctypes.sizeof(info)

# Call it
if GetCursorInfo(ctypes.byref(info)):
    if info.flags & 0x00000001:
        pass  # The cursor is showing
else:
    pass  # Error occurred (invalid structure size?)

谢谢,这非常好,可以从python调用。