#!usr/bin/python
# -*- coding: utf-8 -*-
import pyautogui
# 获取屏幕宽高
screenWidth, screenHeight = pyautogui.size()
print(screenHeight, screenWidth)
# 获取当前鼠标位置
currentMouseX, currentMouseY = pyautogui.position()
print(currentMouseX, currentMouseY)
# 移动鼠标到屏幕中心,原点在屏幕左上角
pyautogui.moveTo(screenWidth / 2, screenHeight / 2)
# 点击坐标所在地方,不填坐标表示点击当前位置
# 在(x,y)处点击鼠标左键、右键、中键
# 但不推荐使用这种方法,下面这种方法效果更好
# pyautogui.moveTo(x,y,duration=t)
# pyautogui.click()
pyautogui.click(800, 50)
pyautogui.moveTo(screenWidth / 2, screenHeight / 2)
pyautogui.click()
# 相对于鼠标当前位置左移50像素,下移200,duration在10秒内缓慢移动到目标位置
pyautogui.moveRel(50, 200, duration=10)
# 点击
pyautogui.mouseDown() # 按下鼠标按键(左键)
pyautogui.mouseUp() # 释放鼠标按键(左键)
pyautogui.doubleClick() # 双击鼠标左键
pyautogui.rightClick() # 单击鼠标右键
pyautogui.middleClick() # 单击鼠标中键
pyautogui.dragTo(50, 60, 2) # 将鼠标拖动到指定位置#x,y:x坐标,y坐标
pyautogui.dragRel(50, 60, 2) # 将鼠标拖动到相对当前位置的位置 #x,y:水平移动,垂直移动
x,y = pyautogui.position()
pyautogui.scroll(x,y-100)
# pyautogui.typewrite("aaa") #向文本框发送字符串
#可选的duration参数在输入单个字符之间添加短暂的时间暂停
#Attention:只能用于输入英文
#截图,获取像素点
img = pyautogui.screenshot()
color = img.getpixel((100,100))
# 获取图片的位置
x,y,width,height = pyautogui.locateOnScreen('a.png')