复制import re
import pyautogui
import time
command_map = {
'MoveTo': 'pyautogui.moveTo',
'LeftClick': 'pyautogui.click',
'LeftDown': 'pyautogui.mouseDown',
'LeftUp': 'pyautogui.mouseUp',
'KeyDown': 'pyautogui.keyDown',
'KeyUp': 'pyautogui.keyUp',
'Delay': 'time.sleep',
'MouseWheel': 'pyautogui.scroll',
'Press': 'pyautogui.press'
}
command_pattern = re.compile(r"(\w+)\s+(.*)")
def parse_command(command):
match = command_pattern.match(command)
if match:
cmd_type = match.group(1)
args = match.group(2)
if cmd_type in command_map:
if cmd_type == 'MoveTo':
x, y = map(int, args.split(','))
return f"{command_map[cmd_type]}({x}, {y})"
elif cmd_type == 'LeftClick':
return f"{command_map[cmd_type]}()"
elif cmd_type == 'LeftDown':
return f"{command_map[cmd_type]}()"
elif cmd_type == 'LeftUp':
return f"{command_map[cmd_type]}()"
elif cmd_type == 'KeyDown':
key = args.strip().strip('"')
return f"{command_map[cmd_type]}('{key}')"
elif cmd_type == 'KeyUp':
key = args.strip().strip('"')
return f"{command_map[cmd_type]}('{key}')"
elif cmd_type == 'Delay':
delay = float(args) / 1000
return f"{command_map[cmd_type]}({delay})"
elif cmd_type == 'MouseWheel':
direction = int(args)
return f"{command_map[cmd_type]}({direction})"
elif cmd_type == 'Press':
key = args.strip().strip('"')
return f"{command_map[cmd_type]}('{key}')"
return None
def convert_script(script_lines):
python_code = []
for line in script_lines:
line = line.strip()
if line:
python_line = parse_command(line)
if python_line:
python_code.append(python_line)
return python_code
def read_script_file(file_path):
with open(file_path, 'r', encoding='gbk') as file:
script_lines = file.readlines()
return script_lines
def write_python_file(python_code, output_file):
with open(output_file, 'w', encoding='utf-8') as file:
file.write("import pyautogui\n")
file.write("import time\n\n")
file.write("pyautogui.PAUSE = 0.01\n\n")
file.write("def run_macro():\n")
for line in python_code:
file.write(f" {line}\n")
file.write("\nrun_macro()\n")
def main():
script_file = r'D:\vx_video\我录制的脚本1_202410141542.Q'
output_file = 'generated_script.py'
script_lines = read_script_file(script_file)
python_code = convert_script(script_lines)
write_python_file(python_code, output_file)
if __name__ == "__main__":
main()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2020-10-14 python在linux环境下安装skimage
2020-10-14 python识别视频黑屏或者低清晰度
2019-10-14 MYSQL事件隔离级别以及复读,幻读,脏读的理解
2019-10-14 前端实现文件下载所有方式
2019-10-14 vue-cli中使用jquery
2019-10-14 audio标签以及audio对象