#ahk ``` ahk !c::hyf_onekeyWindow("C:\Program Files\Google\Chrome\Application\chrome.exe", "Chrome_WidgetWin_1", "\S") ;注意修改路径 !`::hyf_onekeyWindow("C:\Users\liaoyourong\AppData\Local\Obsidian\Obsidian.exe", "Chrome_WidgetWin_1", "\S") ;注意修改路径 !s::hyf_onekeyWindow("F:\Seafile\bin\seafile-applet.exe", "Qt5151QWindowIcon", "\S") ;注意修改路径 !n::hyf_onekeyWindow("C:\Program Files\Notepad++\notepad++.exe", "Notepad++", "\S") ;注意修改路径 !o::hyf_onekeyWindow("C:\Users\liaoyourong\Downloads\mcool\mcool.exe", "TMainForm", "\S") ;注意修改路径 !p::hyf_onekeyWindow("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe", "ConsoleWindowClass", "\S") ;注意修改路径 !v::hyf_onekeyWindow("C:\Users\liaoyourong\AppData\Local\Programs\Microsoft VS Code\Code.exe", "Chrome_WidgetWin_1", "\S") ;注意修改路径 !j::hyf_onekeyWindow("C:\Users\liaoyourong\AppData\Local\TotalCMD64\Totalcmd64.exe", "TTOTAL_CMD", "\S") ;注意修改路径 !k::hyf_onekeyWindow("C:\Users\liaoyourong\Downloads\Pure Codec\x64\PotPlayerMini64.exe", "PotPlayer64", "\S") ;注意修改路径 ^u::hyf_onekeyWindow("C:\Program Files\Unity Hub\Unity Hub.exe", "Chrome_WidgetWin_1", "\S") ;注意修改路径 !g::hyf_onekeyWindow("C:\Users\liaoyourong.ZGAME1\Downloads\Godot_v3.5.2-stable_win64.exe\Godot_v3.5.2-stable_win64.exe", "Engine", "\S") ;注意修改路径 ^b::run ms-settings:bluetooth ; ^m::hyf_onekeyWindow("\\192.168.4.250\项目资源\美术资源\躲猫猫\动作\专业软件\3DMax2021\3ds max 2021替换破解补丁\3dsmax\3dsmax.exe", "Qt5QWindowIcon", "\S") ;注意修改路径 XButton1:: !Left XButton2:: !Right hyf_onekeyWindow(exePath, titleClass := "", titleReg := "") { ;有些窗口用Ahk_exe exeName判断不准确,所以自定义个titleClass SplitPath, exePath, exeName, , , noExt If !hyf_processExist(exeName) { ;hyf_tooltip("启动中,请稍等...") Run,% exePath ;打开后自动运行 TODO funcName := noExt . "_runDo" If IsFunc(funcName) { ;hyf_tooltip("已自动执行函数:" . funcName) Func(funcName).Call() } Else If titleClass { WinWait, Ahk_class %titleClass%, , 1 WinActivate Ahk_class %titleClass% } } Else If WinActive("Ahk_exe " . exeName) { funcName := noExt . "_hideDo" If IsFunc(funcName) Func(funcName).Call() WinHide ;激活鼠标所在窗口 TODO MouseGetPos, , , idMouse WinActivate Ahk_id %idMouse% } Else { If titleReg titleClass := "Ahk_id " . hyf_getMainIDOfProcess(exeName, titleClass, titleReg) Else If titleClass titleClass := "Ahk_class " . titleClass Else titleClass := "Ahk_exe " . exeName WinShow %titleClass% WinActivate %titleClass% funcName := noExt . "_activeDo" If IsFunc(funcName) { ;hyf_tooltip("已自动执行函数:" . funcName) Func(funcName).Call() } } } hyf_processExist(n) ;判断进程是否存在(返回PID) { ;n为进程名 Process, Exist, %n% ;比IfWinExist可靠 Return ErrorLevel } hyf_tooltip(str, t := 1, ExitScript := 0, x := "", y := "") ;提示t秒并自动消失 { t *= 1000 ToolTip, %str%, %x%, %y% SetTimer, hyf_removeToolTip, -%t% If ExitScript { Gui, Destroy Exit } } hyf_getMainIDOfProcess(exeName, cls, titleReg := "") ;获取类似chrome等多进程的主程序ID { DetectHiddenWindows, On WinGet, arr, List, Ahk_exe %exeName% Loop,% arr { n := arr%A_Index% WinGetClass, classLoop, Ahk_id %n% ;MsgBox,% A_Index . "/" . arr . "`n" . classLoop . "`n" . cls FoundPos := InStr(cls, classLoop [, CaseSensitive = false, StartingPos = 1, Occurrence = 1]) If (classLoop = cls) { If !StrLen(titleReg) ;不需要判断标题 Return n WinGetTitle, titleLoop, Ahk_id %n% ;MsgBox,% A_Index . "/" . arr . "`n" . classLoop . "`n" . titleLoop If (titleLoop ~= titleReg) Return n } Continue } Return False } hyf_removeToolTip() ;清除ToolTip { ToolTip } !w:: WinGet, active_id, PID, A run, taskkill /PID %active_id% /F,,Hide return !u:: Gui, Destroy Gui +AlwaysOnTop counter := 1 array := [] has = 0 nowCount = 0 WinGet, vWinList, List, ahk_class UnityContainerWndClass Loop, %vWinList% { nowCount := nowCount + 1 } if (nowCount <= 1) { hyf_onekeyWindow("C:\Program Files\Unity 2020.3.32f1c1\Editor\Unity.exe", "UnityContainerWndClass", "\S") ;注意修改路径 } else { Loop, %vWinList% { hWnd := vWinList%A_Index% has := 1 array[counter] := hWnd WinGetTitle, title, ahk_id %hWnd% text = %title% Loop, Parse, text, `, { Gui Add, Button, gChoice,%counter%.%A_LoopField% break } counter := counter + 1 } if (has == 1) { Gui, Show, AutoSize Center } } Return !r:: Gui, Destroy Gui +AlwaysOnTop WinGet, vWinList, List, ahk_class SunAwtFrame has = 0 counter := 1 array := [] nowCount = 0 Loop, %vWinList% { nowCount := nowCount + 1 } if (nowCount <= 1) { hyf_onekeyWindow("C:\Program Files\JetBrains\JetBrains Rider 2020.2.4\bin\rider64.exe", "SunAwtFrame", "\S") ;注意修改路径 } else { Loop, %vWinList% { hWnd := vWinList%A_Index% has := 1 array[counter] := hWnd WinGetTitle, title, ahk_id %hWnd% text = %title% Loop, Parse, text, `" " { Gui Add, Button, gChoice,%counter%.%A_LoopField% break } counter := counter + 1 } if (has == 1) { Gui, Show, AutoSize Center } } Return Choice: text = %A_GuiControl% Loop, Parse, text, `. { id := % array[A_LoopField] WinGetTitle, title, ahk_id %id% WinActivate,ahk_id %id% break } Gui, Destroy Return !Esc:: Gui, Destroy Return ```