对于使用左手的用户来说,在Windows上将鼠标按钮设置为右键而不是左键可能会发生互换。有什么Python代码可以让我检测到这个设置呢?
对于C++和C#,也有类似的问题:
对于使用左手的用户来说,在Windows上将鼠标按钮设置为右键而不是左键可能会发生互换。有什么Python代码可以让我检测到这个设置呢?
对于C++和C#,也有类似的问题:
如果鼠标按钮已经交换,此函数将返回True
,否则返回False
:
import ctypes
def mouse_is_swapped():
# GetSystemMetrics() with SM_SWAPBUTTON docs from MSDN: "Nonzero if the meanings of the left and right mouse buttons are swapped; otherwise, 0."
SM_SWAPBUTTON = 23
return ctypes.windll.user32.GetSystemMetrics(SM_SWAPBUTTON) != 0
这段代码仅使用标准库,不需要任何第三方包,如pywin32。
import win32api, win32con, win32gui
swapped = win32api.GetSystemMetrics(win32con.SM_SWAPBUTTON)
win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEBUTTONSWAP,not swapped)
input("Restored" if swapped else "Swapped")
win32gui.SystemParametersInfo(win32con.SPI_SETMOUSEBUTTONSWAP,1,flags)
ctypes.windll.user32.SystemParametersInfoA(win32con.SPI_SETMOUSEBUTTONSWAP,1,0,flags)