我尝试在程序中使用鼠标按钮 4 和 5,但我只能使用 pyautogui 的右、左和中按钮,我需要另一个库吗?或者是什么?有人可以帮助我吗?
while True:
data=conexion.read(size=1)
if data ==bytes('7','utf-8'):
pyautogui.hotkey('ctrl', 'c')
elif data == bytes('4','utf-8'):
pyautogui.hotkey('ctrl', 'v')
elif data == bytes('8','utf-8'):
pyautogui.hotkey('ctrl', 'f')
elif data == bytes('C', 'utf-8'):
pyautogui.hotkey('ctrl', 'u')
elif data == bytes('*', 'utf-8'):
buscar_cs()
elif data == bytes('A', 'utf-8'):
for i in range(5):
pyautogui.moveTo(777,363)
pyautogui.click(x=777,y=363,button='middle')
pyautogui.scroll(-244)
time.sleep(0.50)
elif data == bytes('2', 'utf-8'):
for i in range(5):
pyautogui.moveTo(1022,284)
pyautogui.click(x=1022,y=284,button='left')
pyautogui.scroll(-244)
time.sleep(0.25)
elif data == bytes('D','utf-8'):
pyautogui.alert(text="Cerrado", title='ALERTA', button='OK')
break
非常感谢
最佳答案
我能做到!但我们需要另一个名为“pynput”的库。
Button.x1 和 Button.x2 是鼠标按钮 4 和 5
按键代码:
import time
from pynput.mouse import Button, Controller
#press boton
mouse=Controller()
mouse.click(Button.x1)
time.sleep(1)
mouse.click(Button.x2)
time.sleep(1)
监听代码:
import time
from pynput import mouse
def on_click(x, y, button, pressed):
if pressed == True and str(button)=="Button.x1":
print("pressed x1")
return
listener = mouse.Listener(
on_click=on_click)
listener.start()
while True:
time.sleep(0.2)
祝你好运!
关于python - 我如何在 python 中使用鼠标按钮 4-5(玩家)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73297856/