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()
相关推荐
牧羊狼的狼3 小时前
React 中的 HOC 和 Hooks
前端·javascript·react.js·hooks·高阶组件·hoc
知识分享小能手4 小时前
React学习教程,从入门到精通, React 属性(Props)语法知识点与案例详解(14)
前端·javascript·vue.js·学习·react.js·vue·react
luckys.one4 小时前
第9篇:Freqtrade量化交易之config.json 基础入门与初始化
javascript·数据库·python·mysql·算法·json·区块链
魔云连洲4 小时前
深入解析:Vue与React的异步批处理更新机制
前端·vue.js·react.js
mCell5 小时前
JavaScript 的多线程能力:Worker
前端·javascript·浏览器
大翻哥哥6 小时前
Python 2025:量化金融与智能交易的新纪元
开发语言·python·金融
超级无敌攻城狮6 小时前
3 分钟学会!波浪文字动画超详细教程,从 0 到 1 实现「思考中 / 加载中」高级效果
前端
zhousenshan7 小时前
Python爬虫常用框架
开发语言·爬虫·python
excel7 小时前
用 TensorFlow.js Node 实现猫图像识别(教学版逐步分解)
前端
IMER SIMPLE7 小时前
人工智能-python-深度学习-经典神经网络AlexNet
人工智能·python·深度学习