-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
93 lines (72 loc) · 3.07 KB
/
Copy pathmain.py
File metadata and controls
93 lines (72 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import tkinter as tk
import pyautogui
import threading
import time
import re
import ctypes
def auto_input():
# Get and filter text
raw_content = text_box.get("1.0", tk.END)
filtered = re.sub(r'[\u4e00-\u9fff\u3000-\u303F\uFF00-\uFFEF]', '', raw_content)
filtered = re.sub(r'[,。!?、;:“”‘’()《》〈〉【】『』「」—…¥]', '', filtered)
filtered = filtered.strip()
if filtered:
def run():
try:
# Wait for 2 seconds before starting
status_var.set("等待2秒...")
time.sleep(2)
status_var.set("输入中...")
# Set keyboard layout to English
user32 = ctypes.windll.user32
thread_id = ctypes.windll.kernel32.GetCurrentThreadId()
original_layout = user32.GetKeyboardLayout(thread_id)
english_layout = user32.LoadKeyboardLayoutW('00000409', 1)
user32.ActivateKeyboardLayout(english_layout, 0)
# Type the filtered text
pyautogui.write(filtered, interval=0.0)
# Restore original keyboard layout
user32.ActivateKeyboardLayout(original_layout, 0)
status_var.set("输入完成!")
except Exception as e:
status_var.set(f"报错: {e}")
threading.Thread(target=run).start()
else:
status_var.set("没有可输入的内容。")
root = tk.Tk()
root.title("AutoInput Tool")
root.geometry("800x600")
# 创建Frame用于放置text_box和滚动条
text_frame = tk.Frame(root)
text_frame.pack(pady=2, expand=True, fill=tk.BOTH)
# 创建滚动条
x_scroll = tk.Scrollbar(text_frame, orient=tk.HORIZONTAL)
y_scroll = tk.Scrollbar(text_frame, orient=tk.VERTICAL)
text_box = tk.Text(text_frame, height=10, width=40, wrap=tk.NONE, xscrollcommand=x_scroll.set, yscrollcommand=y_scroll.set)
text_box.grid(row=0, column=0, sticky='nsew')
y_scroll.config(command=text_box.yview)
x_scroll.config(command=text_box.xview)
y_scroll.grid(row=0, column=1, sticky='ns')
x_scroll.grid(row=1, column=0, sticky='ew')
# Frame自适应
text_frame.grid_rowconfigure(0, weight=1)
text_frame.grid_columnconfigure(0, weight=1)
# 设置浅色提示文本
def show_placeholder():
if not text_box.get("1.0", tk.END).strip():
text_box.insert("1.0", "在此输入文本,中文将被自动过滤")
text_box.config(fg="#bbbbbb")
def clear_placeholder(event=None):
if text_box.get("1.0", tk.END).strip() == "在此输入文本,中文将被自动过滤":
text_box.delete("1.0", tk.END)
text_box.config(fg="#000000")
text_box.bind("<FocusIn>", clear_placeholder)
text_box.bind("<FocusOut>", lambda e: show_placeholder())
show_placeholder()
status_var = tk.StringVar()
status_var.set("未运行")
button = tk.Button(root, text="输入", command=auto_input)
button.pack(pady=2)
status_label = tk.Label(root, textvariable=status_var, bd=1, relief=tk.SUNKEN, anchor='w', font=(None, 10), height=1)
status_label.pack(fill=tk.X, side=tk.BOTTOM)
root.mainloop()