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()
相关推荐
墨渊君6 分钟前
React Native 跨平台组件库实践: GlueStack UI 上手指南
前端
DanCheng-studio9 分钟前
毕设 基于机器视觉的驾驶疲劳检测系统(源码+论文)
python·毕业设计·毕设
carpell11 分钟前
【语义分割专栏】3:Segnet实战篇(附上完整可运行的代码pytorch)
人工智能·python·深度学习·计算机视觉·语义分割
晓得迷路了14 分钟前
栗子前端技术周刊第 84 期 - Vite v7.0 beta、Vitest 3.2、Astro 5.9...
前端·javascript·vite
独立开阀者_FwtCoder17 分钟前
最全301/302重定向指南:从SEO到实战,一篇就够了
前端·javascript·vue.js
Moment26 分钟前
给大家推荐一个超好用的 Marsview 低代码平台 🤩🤩🤩
前端·javascript·github
小满zs30 分钟前
Zustand 第三章(状态简化)
前端·react.js
普宁彭于晏32 分钟前
元素水平垂直居中的方法
前端·css·笔记·css3
恋猫de小郭43 分钟前
为什么跨平台框架可以适配鸿蒙,它们的技术原理是什么?
android·前端·flutter
云浪1 小时前
元素变形记:CSS 缩放函数全指南
前端·css