我正在尝试听机器人鼠标运动并打印此信息。 该代码对于实际的鼠标移动(实际移动鼠标)工作正常,但是它不显示机器人鼠标的移动。它仅显示点击信息`
import os
import sys
import time
import random
import logging
import pyautogui as pg
from pynput import mouse
from selenium import webdriver
from pyclick import HumanClicker
from pynput.mouse import Button, Controller
def on_move(x, y):
print('Pointer moved to ({0}, {1})'.format(x, y))
def on_click(x, y, button, pressed):
if pressed:
print('Mouse clicked at ({0}, {1}) with {2}'.format(x, y, button))
def on_scroll(x, y, dx, dy):
print('Scrolled {0} at {1}'.format('down' if dy < 0 else 'up', (x, y)))
# ...or, in a non-blocking fashion:
listener = mouse.Listener(
on_move=on_move,
on_click=on_click,
on_scroll=on_scroll)
listener.start()
hc = HumanClicker()
element = driver.find_element_by_xpath('/html/body/center[2]/a/p')
location = element.location
ax, by = location['x'], location['y']
x_axis = random.randint(900, 1100)
hc.move((ax + x_axis, by + 125), duration=2)
pg.click()
pg.position()
element = driver.find_element_by_xpath('/html/body/center[2]/a/p')
location = element.location
ax, by = location['x'], location['y']
x_axis = random.randint(900, 1000)
hc.move((ax + x_axis, by + 135), duration=1)
pg.click()