import pyautogui
# 获取屏幕分辨率
screen_width, screen_height = pyautogui.size()
print(f"屏幕分辨率为: {screen_width}x{screen_height}")
# 移动鼠标到屏幕中央
center_x, center_y = screen_width / 2, screen_height / 2
pyautogui.moveTo(center_x, center_y, duration=1) # duration参数控制移动时间,单位为秒
# 点击鼠标左键
pyautogui.click()
# 输入文本
pyautogui.typewrite('Hello, World!', interval=0.1) # interval参数控制每个字符之间的间隔时间,单位为秒
# 按下和释放键盘上的某个键
pyautogui.press('enter')
# 截图并保存
screenshot = pyautogui.screenshot()
screenshot.save('screenshot.png')
# 查找屏幕上的图像位置
button_location = pyautogui.locateOnScreen('button.png') # 需要提供一个图像文件作为参考
if button_location:
print(f"按钮位置: {button_location}")
button_center = pyautogui.center(button_location)
pyautogui.click(button_center)
else:
print("未找到按钮")
pyautogui.size()
获取当前屏幕的宽度和高度。pyautogui.moveTo(x, y, duration)
将鼠标移动到指定坐标,duration
参数控制移动的时间。pyautogui.click()
模拟鼠标左键点击。pyautogui.typewrite(text, interval)
输入指定文本,interval
参数控制每个字符之间的间隔时间。pyautogui.press(key)
模拟按键操作。pyautogui.screenshot()
截取屏幕并保存为图片文件。pyautogui.locateOnScreen(image_path)
查找屏幕上是否存在指定图像,并返回其位置。如果找到,则可以进一步操作该图像(例如点击)。上一篇:python pytest框架
下一篇:dotenv python
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站