##本文件需要下列第三方模块:
##pyautogui pyperclip urllib beautifulsoup4 openpyxl
##pyautogui pyperclip urllib beautifulsoup4 openpyxl
import pyautogui as gui
import time,datetime,matplotlib.dates
import os,sys,threading,pyperclip
from urllib import request
import bs4
import openpyxl
import smtplib,imaplib,email
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
gui.PAUSE=0.5 #每次函数调用后暂停0.5秒
gui.FAILSAFE=True #启动自动防故障功能
import time,datetime,matplotlib.dates
import os,sys,threading,pyperclip
from urllib import request
import bs4
import openpyxl
import smtplib,imaplib,email
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
gui.PAUSE=0.5 #每次函数调用后暂停0.5秒
gui.FAILSAFE=True #启动自动防故障功能
#===处理屏幕==================================
def get_screen_size():#获得屏幕大小
width,height=gui.size()
return width,height
def get_screen_size():#获得屏幕大小
width,height=gui.size()
return width,height
def get_screen_shot():#获得屏幕快照
im=gui.screenshot()
return im
im=gui.screenshot()
return im
def get_screen_locate_color(x,y):#获得坐标处的颜色值
im=GetScreenShow()
return im.getpixel((x,y))
im=GetScreenShow()
return im.getpixel((x,y))
def is_screen_locate_color(x,y,r,b,g):#判断坐标处颜色是否给定值
im=GetScreenShow()
return gui.pixelMatchesColor(x,y,(r,b,g))
im=GetScreenShow()
return gui.pixelMatchesColor(x,y,(r,b,g))
def get_png_all_location(PNGfile):#获得图像在屏幕上的所有位置和大小
return list(gui.locateAllOnscreen(PNGfile))
#return [(x1,y1,w1,h1),(x2,y2,w2,h2),(x3,y3,w3,h3)...]
return list(gui.locateAllOnscreen(PNGfile))
#return [(x1,y1,w1,h1),(x2,y2,w2,h2),(x3,y3,w3,h3)...]
#===鼠标操作===================================
def get_mouse_position():#返回鼠标位置(x,y)
return gui.position()
def get_mouse_position():#返回鼠标位置(x,y)
return gui.position()
def click_png(PNGfile,buttonkey='left'):#鼠标点击屏幕上图片位置(默认左键)buttonkey='left','mi
png=gui.locateOnScreen(PNGfile)
if png:
gui.click(gui.center(png),button=buttonkey)
png=gui.locateOnScreen(PNGfile)
if png:
gui.click(gui.center(png),button=buttonkey)
def double_click(PNGfile):#鼠标左键双击屏幕上图片位置
png=gui.locateOnScreen(PNGfile)
if png:
gui.doubleClick(gui.center(png))
png=gui.locateOnScreen(PNGfile)
if png:
gui.doubleClick(gui.center(png))
def right_click(PNGfile): #鼠标右键双击屏幕上图片位置
png=gui.locateOnScreen(PNGfile)
if png:
gui.rightClick(gui.center(png))
png=gui.locateOnScreen(PNGfile)
if png:
gui.rightClick(gui.center(png))
def middle_click(PNGfile):#鼠标中键双击屏幕上图片位置
png=gui.locateOnScreen(PNGfile)
if png:
gui.middleClick(gui.center(png))
#------------------------------------------
def click_position(x,y,buttonkey='left'):#模拟点击(默认左键)buttonkey='left','middle','right'
gui.click(x,y,button=buttonkey)
png=gui.locateOnScreen(PNGfile)
if png:
gui.middleClick(gui.center(png))
#------------------------------------------
def click_position(x,y,buttonkey='left'):#模拟点击(默认左键)buttonkey='left','middle','right'
gui.click(x,y,button=buttonkey)
def double_click(x,y):#模拟左键双击
gui.doubleClick(x,y)
def right_click(x,y):#模拟右键双击
gui.rightClick(x,y)
gui.doubleClick(x,y)
def right_click(x,y):#模拟右键双击
gui.rightClick(x,y)
def middle_click(x,y):#模拟中键双击
gui.middleClick(x,y)
gui.middleClick(x,y)
def mouse_down(x,y,buttonkey='left'):#模拟在指定位置按下指定鼠标键 buttonkey='left','middle','right'
gui.mouseDown(x,y,button=buttonkey)
gui.mouseDown(x,y,button=buttonkey)
def mouse_up(x,y,buttonkey='left'):#模拟在指定位置释放指定鼠标键 buttonkey='left','middle','right'
gui.mouseUp(x,y,button=buttonkey)
def drag_rel(dx,dy):#按下左键鼠标拖动(相对原位置)
gui.dragRel(dx,dy,duration=0.2)
gui.mouseUp(x,y,button=buttonkey)
def drag_rel(dx,dy):#按下左键鼠标拖动(相对原位置)
gui.dragRel(dx,dy,duration=0.2)
def drag_to(x,y):#按下左键鼠标拖动(绝对位置)
gui.dragTo(x,y,duration=0.2)
gui.dragTo(x,y,duration=0.2)
def move_to(x,y):#移动鼠标到X,Y坐标
gui.moveTo(x,y)
gui.moveTo(x,y)
def move_rel(dx,dy):#移动鼠标到相对原坐标的DX、DY处
gui,moverRel(dx,dy)
def scroll_window(n):#窗口滚动
gui.scroll(n)#n为正表示向上滚动,为负表示向下滚动
gui,moverRel(dx,dy)
def scroll_window(n):#窗口滚动
gui.scroll(n)#n为正表示向上滚动,为负表示向下滚动
#===键盘操作=====================================
##PyKeyboard键盘键字符串 含义
##'a', 'A', '1','!', '@', '#',等等 单个字符的键
##'enter'(or 'return' or '\n') 回车键
##'esc' Esc 键
##'shiftleft', 'shiftright' 左右 Shift 键
##'altleft', 'altright' 左右 Alt 键
##'ctrlleft', 'ctrlright' 左右Ctrl 键
##'tab'(or '\t') Tab 键
##'backspace', 'delete' Backspace 和 Delete 键
##'pageup', 'pagedown' Page Up 和 Page Down 键
##'home', 'end' Home 和 End 键
##'up', 'down', 'left', 'right' 上下左右箭头键
##'f1', 'f2', 'f3',等等 F1 至 F12 键
##'volumemute', 'volumedown', 'volumeup' 静音、减小音量、放大音量键(有些键盘没有这些键,但你
##的操作系统仍能理解这些模拟的按键)
##'pause'
##PyKeyboard键盘键字符串 含义
##'a', 'A', '1','!', '@', '#',等等 单个字符的键
##'enter'(or 'return' or '\n') 回车键
##'esc' Esc 键
##'shiftleft', 'shiftright' 左右 Shift 键
##'altleft', 'altright' 左右 Alt 键
##'ctrlleft', 'ctrlright' 左右Ctrl 键
##'tab'(or '\t') Tab 键
##'backspace', 'delete' Backspace 和 Delete 键
##'pageup', 'pagedown' Page Up 和 Page Down 键
##'home', 'end' Home 和 End 键
##'up', 'down', 'left', 'right' 上下左右箭头键
##'f1', 'f2', 'f3',等等 F1 至 F12 键
##'volumemute', 'volumedown', 'volumeup' 静音、减小音量、放大音量键(有些键盘没有这些键,但你
##的操作系统仍能理解这些模拟的按键)
##'pause'