pyautogui自动化鼠标键盘操作

pyautogui,用来写自动化脚本,比按键精灵更方便。pyautogui.position()可以获取当前鼠标位置。pyautogui不支持中文输入,利用 pyperclip从剪切板粘贴输入。

python 复制代码
# -*- coding: utf-8 -*-
import time
import os
import traceback
import logging
import pyautogui
from logging.handlers import RotatingFileHandler
import pyperclip
pos={"H15":(724,507)
,"D01":(362,507)
,"ELY01":(362,507)
,"ELY36":(486,739)
,"C01":(358,350)}
h=(742-507)/9
w=60
def set_input(value):
    with pyautogui.hold('ctrl'):  # Press the Shift key down and hold it.
        pyautogui.press(['a'])  # Press the left arrow key 4 times.
    pyperclip.copy(value)
    time.sleep(0.3)
    pyautogui.hotkey('Ctrl', 'V')
def fg():
    mouse_click(505,217)
    mouse_click(549,426)#open fg
    set_input("#F95E5E")
    mouse_click(457,441)#open fg
def fg_clear():
    mouse_click(505,217)
    mouse_click(549,426)#open fg
    set_input("#000000")
    mouse_click(457,441)#open fg
def mouse_click(x,y):
    pyautogui.moveTo(x,y)#open fg
    pyautogui.click()
    time.sleep(0.3)
def bg_clear():
    mouse_click(557,217)#open fg
    mouse_click(549+52,426)#open fg
    set_input("#FFFFFF")
    mouse_click(457,441)#open fg
def bg():
    mouse_click(557,217)#open fg
    # time.sleep(0.200)
    mouse_click(549+52,426)#open fg
    set_input("#F95E5E")
    mouse_click(457,441)#open fg
def bj():
    mouse_click(1083,224)#open fg
    mouse_click(908,238)#open fg
    set_input("1")
    mouse_click(1012,299)#open fg
    set_input("#32F92C")
    mouse_click(1008,341)#open fg
    set_input("#32F92C")
    mouse_click(1167,432)#open fg
    # mouse_click(457,441)#open fg
def gs(value):
    mouse_click(411,257)#open fg
    set_input(value)
    mouse_click(330,261)#open fg
def main():
    fg()
    bg()
def toggle_one(x,y):
    logging.info(["pos",x,y])
    mouse_click(x,y)
    fg()
    bg()
    bj()
def toggle_c():
    (x0,y0)=pos["C01"]
    x=x0
    y=y0
    i=1
    while True:
        toggle_one(x,y)
        istr="%02d" % i
        v="=[公式].[if] where [设备编号]='C"+istr+"'"
        logging.info(v)
        gs(v)
        x=x+w*2
        i+=1
        if i>5:
            break
def toggle_d():
    (x0,y0)=pos["D01"]
    x=x0
    y=y0
    i=1
    while True:
        toggle_one(x,y)
        istr="%02d" % i
        v="=[公式].[if] where [设备编号]='D"+istr+"'"
        logging.info(v)
        gs(v)
        y=y+h
        i+=2
        if i>13:
            break
    x=x0+w*2
    y=y0
    i=2
    while True:
        toggle_one(x,y)
        istr="%02d" % i
        v="=[公式].[if] where [设备编号]='D"+istr+"'"
        gs(v)
        y=y+h
        i+=2
        if i>14:
            break  
def toggle_ely1():
    (x0,y0)=pos["ELY01"]
    x=x0
    y=y0
    num=1
    for j in range(5):
        y=y0
        for i in range(7):
            toggle_one(x,y)
            istr="%02d" % num
            v="=[公式].[if] where [设备编号]='ELY"+istr+"'"
            logging.info(v)
            gs(v)
            y=y-h
            num+=1
        x=x+w*2
def toggle_ely36():
    (x0,y0)=pos["ELY36"]
    x=x0
    y=y0
    num=36
    for j in range(2):
        y=y0
        for i in range(7):
            toggle_one(x,y)
            istr="%02d" % num
            v="=[公式].[if] where [设备编号]='ELY"+istr+"'"
            logging.info(v)
            gs(v)
            y=y-h
            num+=1
            if num>48:
                return
        x=x-w*2

def toggle_h():
    (x0,y0)=pos["H15"]
    x=x0
    y=y0
    i=15
    while True:
        toggle_one(x,y)
        v="=[公式].[if] where [设备编号]='H"+str(i)+"'"
        logging.info(v)
        gs(v)
        y=y+h
        i+=2
        if i>33:
            break
    x=x0+w*2
    y=y0
    i=16
    while True:
        toggle_one(x,y)
        v="=[公式].[if] where [设备编号]='H"+str(i)+"'"
        gs(v)
        y=y+h
        i+=2
        if i>34:
            break
if __name__=="__main__":
    import logging
    import sys
    handlers=[RotatingFileHandler(filename="report.log", maxBytes=10*1024*1024, encoding='utf-8',backupCount=3),logging.StreamHandler(sys.stdout)]
    logging.basicConfig(level=logging.DEBUG,
                    format = '%(asctime)s - %(name)s - %(levelname)s -%(funcName)s - %(message)s',
                    handlers=handlers)
    logging.info('begin')
    # toggle_h()
    # toggle_d()
    # toggle_one(724,536)
    # enum1()
    # bj()
    # gs("abc")
    # bg_clear()
    # fg_clear()
    # toggle_c()
    toggle_ely36()
相关推荐
夜焱辰8 小时前
浏览器端 Agent 的文件版本管理:不用 Git,基于 OPFS + SQLite 自己造了一个
前端·人工智能
梦想的颜色8 小时前
TypeScript 完全指南(下):从类型体操到生产级配置
前端·javascript·typescript
lifloveyou9 小时前
table接口结构
python
Hi~晴天大圣10 小时前
npm使用介绍
前端·npm·node.js
888CC++10 小时前
如何在 C 语言中进行程序调试?
前端·javascript·算法
Warson_L10 小时前
class 扩展
python
喵个咪11 小时前
基于 Taro 的 Headless CMS 多端前端架构:技术解析与二次开发导引
前端·react.js·taro
狂炫冰美式11 小时前
你还在古法PPT吗,试试HTML呢?免费编辑导出工具给 xdm 放这了
前端·后端·github
前端与小赵11 小时前
Python 数据结构陷阱与复数运算优化:列表、元组、字典成员操作辨析及 NumPy 高效实践
python
天天进步201511 小时前
Python全栈项目--基于深度学习的视频目标跟踪系统
python·深度学习·音视频