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')
# 查找屏幕上的图像位置
location = pyautogui.locateOnScreen('target_image.png')
if location:
print(f"找到图像位置: {location}")
else:
print("未找到图像")
# 显示消息框
pyautogui.alert(text='操作完成', title='提示', button='OK')
pyautogui.size()
返回一个包含屏幕宽度和高度的元组。pyautogui.moveTo(x, y, duration)
将鼠标移动到指定坐标 (x, y)
,duration
参数控制移动的时间。pyautogui.click()
模拟鼠标左键单击。pyautogui.typewrite(text, interval)
模拟键盘输入文本,interval
参数控制每个字符之间的间隔时间。pyautogui.press(key)
模拟按下和释放指定的键盘按键。pyautogui.screenshot()
截取当前屏幕并返回一个 PIL 图像对象,可以使用 .save()
方法保存图像。pyautogui.locateOnScreen(image_path)
在屏幕上查找指定图像的位置,并返回其矩形区域。pyautogui.alert()
显示一个带有自定义文本、标题和按钮的消息框。上一篇:python 字典合并
下一篇:python ctypes
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站