Python - 如何在不移动光标的情况下刺激鼠标点击?

问题描述 投票:0回答:2

我正在尝试使用

pyautogui
并单击屏幕上的某个区域,但我希望它在不物理移动光标的情况下单击,有点像无形的单击。到目前为止,我不知道该怎么做,只有典型的自动点击并将光标位置移动到该区域。

我使用了以下内容:

pyautogui.click(x=100, y=13)

但是,它将光标移动到该特定位置而不是发送点击。有什么可能的方法可以使用 pyautogui 或任何其他模块吗?

python python-3.x automation click pyautogui
2个回答
0
投票
import pyautogui

# Get the x and y coordinates of the target location
x = 100
y = 13

# Move the cursor to the target location
pyautogui.moveTo(x, y)

# Simulate a left mouse button down at the target location
pyautogui.mouseDown(button='left', x=x, y=y)

# Simulate a left mouse button up at the target location
pyautogui.mouseUp(button='left', x=x, y=y)

0
投票

这通常适用于主显示器。我用右键单击进行了测试。

import pyautogui

# Get the size of the primary monitor.
screenWidth, screenHeight = pyautogui.size() 
print(screenWidth, screenHeight)

pyautogui.click(100, 200, button='right')
© www.soinside.com 2019 - 2024. All rights reserved.