感谢同行通过了解决思路
废话不多说,直接上代码
import ctypes
# 定义常量
SPI_SETMOUSESPEED = 0x0071
SM_CXSCREEN = 0
SM_CYSCREEN = 1
# 获取屏幕分辨率
screen_width = ctypes.windll.user32.GetSystemMetrics(SM_CXSCREEN)
screen_height = ctypes.windll.user32.GetSystemMetrics(SM_CYSCREEN)
# 设置鼠标速度
def set_mouse_speed(speed):
ctypes.windll.user32.SystemParametersInfoW(SPI_SETMOUSESPEED, 0, speed, 0)
# 获取当前鼠标速度
def get_mouse_speed():
speed = ctypes.c_int()
ctypes.windll.user32.SystemParametersInfoW(SPI_SETMOUSESPEED, 0, ctypes.byref(speed), 0)
return speed.value
# 示例:将鼠标速度设置为2(在范围1-20之间)
set_mouse_speed(2)
# 示例:获取并打印当前鼠标速度
current_speed = get_mouse_speed()
print(f"当前鼠标速度: {current_speed}")
有个问题
有时候运行python的时候,鼠标速度并不能修改成功,不知道为什么,有没有大佬再做深层的研究