[英]Detect if the mouse cursor is hidden or visible by any other application
我想检测鼠标当前是否隐藏,这通常是由Windows上的3D应用程序完成的。 这似乎比听起来更棘手,因为我找不到任何方法来做到这一点。
我希望用Python做这个,但如果不可能,我可以求助于C.谢谢!
GetCursorInfo
函数返回CURSORINFO
结构,该结构具有包含全局游标状态的flags
字段。 这会做你需要的吗? 我不熟悉Python,所以我不知道你是否可以从Python调用这个函数。
您需要调用GetCursorInfo
函数。 这可以使用pywin32库直接完成。 或者,如果您不想安装外部Python库,则可以使用ctypes
模块直接从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?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.