赞
踩
网页禁止粘贴怎么办?
模拟法yyds
import time
import keyboard
from pynput.keyboard import Controller
def simulate_typing(filename):
keyboard = Controller()
with open(filename, 'r', encoding='utf-8') as file:
lines = file.readlines()
# 移除每行的前导空格,并获取最小缩进量
min_indent = float('inf')
for line in lines:
stripped_line = line.lstrip()
if stripped_line:
indent = len(line) - len(stripped_line)
min_indent = min(min_indent, indent)
# 模拟键盘敲击,并进行缩进处理
for line in lines:
stripped_line = line.lstrip()
if stripped_line:
indent = len(line) - len(stripped_line)
adjusted_indent = indent - min_indent # 调整缩进
if adjusted_indent > 0:
keyboard.type(' ' * adjusted_indent) # 输入调整后的缩进
keyboard.type(stripped_line) # 输入去除前导空格的行内容
else:
keyboard.type('\n') # 输入空行
print("代码模拟敲击完成。")
# 使用示例
filename = 'ex3.py' # 替换为你的代码文件名
print("按 Enter 键开始模拟敲击代码...")
keyboard.wait('enter')
simulate_typing(filename)
在这里祝某歌OJ服务器天天报不知名错
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。