pynput 需要属于第三方库,需要手动下载
pip instaii pynput
from pynput import mouse
import time
time.sleep(1) # 给你一秒让你移到想测试的地方
with mouse.Events() as events: # 操作鼠标,则触发
event = events.get(3) # 设置超时时间为3秒
if event is None:
print('超时')
else:
print(f'{event}') # 鼠标坐标,点击鼠标,上滑操作
from pynput import mouse
import time
while 1:
time.sleep(1) # 给你一秒让你移到想测试的地方
with mouse.Events() as events: # 操作鼠标,则触发
event = events.get(3) # 设置超时时间为3秒
if event is None:
print('超时')
else:
print(f'{event}') # 鼠标坐标,点击鼠标,上滑操作
from pynput.mouse import Button, Controller as mouse_d
mouse= mouse_d()
mouse.click(Button.left) # 点击左键
mouse.click(Button.left,2) # 双击左键
mouse.press(Button.right) # 按住右键
mouse.release(Button.right) # 按住右键
print(mouse.position) # 鼠标位置
mouse.position = (500,500) # 移到到500,500的坐标上
mouse.move(200,300) # 相对移动x+200,y+300
mouse.press(Button.left) # 按下左键
mouse.move(300, 2) # 移动相对位置
mouse.release(Button.left) # 公开左键
import pynput
ctr = pynput.mouse.Controller()
ctr.scroll(0, 100) #向上移动100个单位
ctr.scroll(0, -100) #向下移动100个单位