SystemParametersInfoSPI_GETMOUSE python调用 后鼠标的属性全是0
这可能是因为您的代码中缺少必要的参数或调用顺序不正确。请确保您正确地调用了SystemParametersInfo函数,并提供了正确的参数。
以下是一个示例代码,可以帮助您正确地调用SystemParametersInfo函数来获取鼠标属性:
import ctypes
SPI_GETMOUSE = 0x0003
SPIF_UPDATEINIFILE = 0x01
SPIF_SENDCHANGE = 0x02
# Define the necessary structures and types
class MOUSEINFO(ctypes.Structure):
_fields_ = [("cbSize", ctypes.c_uint),
("dwFlags", ctypes.c_uint),
("dwExtraInfo", ctypes.c_ulong),
("dx", ctypes.c_ulong),
("dy", ctypes.c_ulong),
("mouseData", ctypes.c_ulong)]
MOUSEINFO_SIZE = ctypes.sizeof(MOUSEINFO)
# Call SystemParametersInfo to get the mouse info
mouse_info = MOUSEINFO()
mouse_info.cbSize = MOUSEINFO_SIZE
result = ctypes.windll.user32.SystemParametersInfoW(SPI_GETMOUSE, 0, ctypes.byref(mouse_info), 0)
# Check if the call was successful
if result:
print("Mouse properties:")
print(" Flags: {}".format(mouse_info.dwFlags))
print(" Extra info: {}".format(mouse_info.dwExtraInfo))
print(" X position: {}".format(mouse_info.dx))
print(" Y position: {}".format(mouse_info.dy))
print(" Mouse data: {}".format(mouse_info.mouseData))
else:
print("Error calling SystemParametersInfo: {}".format(ctypes.WinError()))
请注意,此示例代码使用了ctypes库,该库允许您调用Windows API函数。在调用SystemParametersInfo函数时,我们需要将参数传递给函数,并使用byref函数将结构体传递给函数。最后,我们检查函数调用是否成功,并打印获取到的鼠标属性。
原文地址: https://www.cveoy.top/t/topic/bu4B 著作权归作者所有。请勿转载和采集!