Skip to content

Commit

Permalink
新增:自定义延迟功能优化并修改部分注释
Browse files Browse the repository at this point in the history
  • Loading branch information
intmian committed Jan 3, 2024
1 parent 10613ab commit 4e52e1a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
25 changes: 16 additions & 9 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ def on_select_cast(self,cast_name,cast_list):
sequence = ""
for key in combo["sequence"]:
if key[0] == '`':
for i in range(int(key[1:])):
sequence += "空"
sequence += f"空{key[1:]}ms"
else:
sequence += key
sequence += " "
str_list.append(f"{trigger_key}: {sequence}")
str_list.append("<双击新增|双击已有项删除>")
self.combobox.set(cast_name)
Expand Down Expand Up @@ -322,26 +322,33 @@ def add_combo(self):
root.withdraw()
root.update_idletasks()
trigger_key = simpledialog.askstring("新增快捷键", "请输入触发键,额外支持鼠标侧键后x1,前x2",parent=root)
if trigger_key == None:
if trigger_key == None or trigger_key == "":
return
# 检测是否包含空格
if " " in trigger_key:
simpledialog.messagebox.showerror("新增方案", "触发键不能包含空格")
return
# 检测是否已经存在
for combo in self.quick_mgr.quick_casts[self.now_choose_cast]:
if combo["trigger_key"] == trigger_key:
simpledialog.messagebox.showerror("新增方案", "已经存在该快捷键,请先删除旧的")
return
root.update_idletasks()
sequence = simpledialog.askstring("新增快捷键", "请输入按键序列,额外支持`n表示空n次,以空格分隔",parent=root)
if sequence == None:
sequence = simpledialog.askstring("新增快捷键", "请输入按键序列,额外支持`n表示空n ms,对应技能后摇等,以空格分隔",parent=root)
if sequence == None or sequence == "":
return

sequence = sequence.split()
# 检查是否存在是否存在大于一个键的
for key in sequence:
if key[0] == "`" and len(key) == 2:
pass
if key[0] == "`":
# 遍历下是否都为数字,且小于10000
if not key[1:].isdigit() or int(key[1:]) > 10000:
simpledialog.messagebox.showerror("新增方案", "无效的按键序列")
return
elif len(key) > 1:
simpledialog.messagebox.showerror("新增方案", "无效的按键序列")
return
sequence = sequence.split()
self.quick_mgr.add_combo_to_cast(self.now_choose_cast,trigger_key,sequence,self.is_start)
self.ui_mgr.on_add_combo({"trigger_key":trigger_key,"sequence":sequence})

Expand Down Expand Up @@ -372,7 +379,7 @@ def start(self):
def main():
# 打包的程序的实际路径是一个临时目录,所以注释
# os.chdir(os.path.dirname(os.path.realpath(__file__)))
# 如果没有管理员权限就报错
# 如果没有管理员权限就以管理员权限重新启动
if ctypes.windll.shell32.IsUserAnAdmin() == 0:
messagebox.showwarning("警告", "未以管理员身份运行,将以管理员权限重新启动")
# ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
Expand Down
10 changes: 5 additions & 5 deletions quick_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,16 @@ def run_combo(self, combo):
timeline_now = 0
keys = []
for key in combo['sequence']:
if key[0] == "`" and len(key) == 2:
if key[0] == "`":
delay = float(0)
for i in range(int(key[1])):
delay += random.uniform(0.91, 1.09) * self.settings["key_up_interval"]
# 为了提高准确度并且操作更加自然,随机延迟设定如下
delay += random.uniform(0.95, 1.051) * 0.001 * int(key[1:])
timeline_now += delay
continue
keys.append((key,True,timeline_now))
delay = self.settings["key_up_interval"] * random.uniform(0.77, 1.23)
delay = self.settings["key_up_interval"] * random.uniform(0.952, 1.05)
keys.append((key,False,timeline_now+delay))
timeline_now += self.settings["key_interval"] * random.uniform(0.66, 1.34)
timeline_now += self.settings["key_interval"] * random.uniform(0.82, 1.19)
keys.sort(key=lambda x: x[2])
for i,key in enumerate(keys):
if i != 0:
Expand Down

0 comments on commit 4e52e1a

Please sign in to comment.