Stop old thread immediately when new hot key is started
Posted: 10 Jul 2018, 10:08
For multiple hotkeys used in games, new hotkeys may interrupt old threads.
I think of a way to clean up old threads before starting a new hotkey thread.
I think of a way to clean up old threads before starting a new hotkey thread.
Code: Select all
/*
Stop old thread immediately when new hot key is started
2018-07-10 By FeiYue
*/
#NoEnv
#NoTrayIcon
#SingleInstance off
if 0 = 0
ok:="Main"
else
ok:="Sub"
;-----------------------
DetectHiddenWindows, On
Gui, ok:Show, Hide, [%ok%]
Gui, ok:+Hwndmyid
WinGet, list, List, [%ok%] ahk_class AutoHotkeyGUI
Loop, % list {
IfEqual, myid, % id:=list%A_Index%, Continue
WinGet, pid, PID, ahk_id %id%
WinClose, ahk_class AutoHotkey ahk_pid %pid%,, 3
IfWinExist, ahk_id %id%
Process, Close, %pid%
}
DetectHiddenWindows, Off
;-----------------------
if 0 = 0
{
Menu, Tray, Icon
;-- The hotkeys used by the user should be added here
;------------------------------
For k,v in ["F1","F2","F3"]
Hotkey, %v%, %v%
;------------------------------
return
}
if IsLabel(k:=%True%)
Goto, %k%
return
ok() {
static arg:=%True%
if (arg="")
{
Run, %A_AhkPath% "%A_ScriptFullPath%" %A_ThisLabel%
KeyWait, % RegExReplace(A_ThisHotkey,"\W+")
Exit
}
}
;========== Add your hotkey code ==========
F1:
ok() ;-- The first line of each hotkey should add this sentence
Loop {
Sleep, 100
ToolTip, F1-%A_Index%
}
return
F2:
ok()
Loop {
Sleep, 100
ToolTip, F2-%A_Index%
}
return
F3:
ok()
ExitApp
;========== The End ==========
;