栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 写的一个按键精灵工具 特别方便 喜欢拿去

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 写的一个按键精灵工具 特别方便 喜欢拿去

程序可以每隔固定周期时间自动进行操作鼠标、键盘、输入文本等。

屏幕坐标我是用FastStoneCapture软件的“屏幕十字线”功能取的,很方便,其实方法很多,屏幕截图用画图软件也可以。

代码如下:

main.py #主程序

import win32api
import pyautogui
import time
import os
import subprocess
from load_conf import config
print("程序启动")
interval_interval=int(config["interval-interval"])
print("操作周期:%d 秒" % interval_interval)
while 1:
    time.sleep(interval_interval)
    mouse_enable=True if config["mouse-enable"]=="yes" else False
    key_enable=True if config["key-enable"]=="yes" else False
    if mouse_enable:
        print("准备鼠标操作")
        x=int(config["mouse-x"])
        y=int(config["mouse-y"])
        times=int(config["mouse-times"])
        interval=float(config["mouse-interval"])
        action=config["mouse-action"]
        for t in range(times):
            if action=="left":
                pyautogui.leftClick(x=x,y=y,interval=interval)
                print("鼠标左键,(%d,%d)" % (x,y))
            elif action=="right":
                pyautogui.rightClick(x=x, y=y, interval=interval)
                print("鼠标右键,(%d,%d)" % (x, y))
            elif action=="double":
                pyautogui.doubleClick(x=x, y=y, interval=interval)
                print("鼠标双击,(%d,%d)" % (x, y))
    if key_enable:
        print("准备键盘操作")
        word=config["key-word"]
        key=config["key-key"]
        if word:
            pyautogui.typewrite(word,0.2)
            print("键盘输入: %s" % word)
        if key:
            pyautogui.press(key)
            print("键盘操作: %s" % key)

load_conf.py #配置程序

import configparser
import os
cf = configparser.ConfigParser()
cf.read("conf",encoding='utf-8')
config = {
        "interval-interval": cf.get("interval", "interval"),
        "mouse-x": cf.get("mouse", "x"),
        "mouse-y": cf.get("mouse", "y"),
        "mouse-times": cf.get("mouse", "times"),
        "mouse-interval": cf.get("mouse", "interval"),
        "mouse-enable": cf.get("mouse", "enable"),
        "mouse-action": cf.get("mouse", "action"),
        "key-word": cf.get("key", "word"),
        "key-key": cf.get("key", "key"),
        "key-enable": cf.get("key", "enable"),
    }

conf #配置文件

[interval]
interval=10
#秒

[mouse]
x=896
y=743
times=1
interval=1
enable=yes
action=left
#left right double

[key]
word="test"
key=enter
enable=yes

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/917884.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号