Skip to content

Commit

Permalink
新增进程添加功能
Browse files Browse the repository at this point in the history
脚本启动时可以显示当前支持的进程,以及允许用户添加进程
  • Loading branch information
Cey1anze committed Jul 27, 2023
1 parent 7a94f84 commit 73eb58c
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions IME.ahk
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
#Persistent ;
#Persistent ;

ProcessList := ["bfv.exe", "notepad.exe"] ; 在这里添加进程名,注意进程名是否正确以及格式,使用英文逗号
ProcessList := ["bfv.exe", "csgo.exe", "r5apex.exe"]
CapsLocked := 0
LoopActive := 1 ;
LoopActive := 1

ProcessListMsg := "当前已添加的进程有:" . "`n"
For Each, Process in ProcessList
{
ProcessListMsg .= Process . "`n"
}
MsgBox, %ProcessListMsg%

MsgBox, 4, 添加进程, 是否要添加一个exe进程到ProcessList中
IfMsgBox, Yes
{
FileSelectFile, SelectedFile, 3, , 选择exe文件

if (SelectedFile <> "") {
loop, %SelectedFile%
ShortName := A_LoopFileShortName
; 读取文件的内容
FileRead, ScriptContent, IME.ahk

; 匹配ProcessList列表
if (RegExMatch(ScriptContent, "(ProcessList\s*:=\s*\[)(.*)(\])", match)) {
; 提取现有的ProcessList
existingList := match2

; 检查选择的文件是否已经在ProcessList
if (!RegExMatch(existingList, "\b" . ShortName . "\b")) {
; 将选择的文件名追加到ProcessList
newProcessList := existingList . ", " . """" . ShortName . """"
; 替换原来的ProcessList
modifiedScriptContent := RegExReplace(ScriptContent, "(ProcessList\s*:=\s*\[)(.*)(\])", "$1" . newProcessList . "$3")

; 写入修改后的内容回到ahk文件
FileDelete, IME.ahk
FileAppend, %modifiedScriptContent%, IME.ahk, UTF-8
MsgBox, 成功将 %ShortName% 添加到进程列表中!
} else {
MsgBox, 文件 %ShortName% 已经在进程列表中!
}
} else {
MsgBox, 在ahk文件中未找到进程列表
}
} else {
MsgBox, 没有选择任何文件
}
reload
}

Loop
{
Expand Down

0 comments on commit 73eb58c

Please sign in to comment.