如何在 Pynput 中使用侧面鼠标按钮?

Kam*_*oh2 4 python mouse macros pynput

我正在使用 Python 模块 Pynput 制作一个宏,该宏将按下我的侧面按钮之一。有谁知道 Pynput 中的侧面按钮叫什么?例如:

from pynput.mouse import Button, Controller

mouse = Controller()

mouse.press(Button.SIDEBUTTON)
mouse.release(Button.SIDEBUTTON)
Run Code Online (Sandbox Code Playgroud)

SIDEBUTTON 部分应该包含什么内容?

小智 6

所以这个问题有点老了,我也遇到了同样的问题。我弄清楚了这些按钮的名称:

Mouse4 和 Mouse5 的 Button.x1 和 Button.x2。

希望我能帮助你。我用来找到它的脚本就在这里:

from pynput.mouse import Listener
def on_click(x, y, button, pressed):
    if pressed:
       print(button)
   
# Collect events until released
with Listener(on_click=on_click) as listener:
    listener.join()
Run Code Online (Sandbox Code Playgroud)