通过 autohotkey 绑定日常所用软件实现快速切换
- Alt + T 打开 NotePad ++
- Alt + I 打开 IDEA
- Alt + P 打开 PostMan
- …
Example
Shit+F2 显示当前 idea 编辑的项目
以下脚本中程序地址改成自己电脑上的exe所在路径替换即可
;;;中文文档 https://wyagd001.github.io/zh-cn/docs/AutoHotkey.htm
;;;热键 https://wyagd001.github.io/zh-cn/docs/Hotkeys.htm
;;; This script create by https://linux.do/u/ech2o
;Alt + I 打开 Idea
!I::
ifWinExist,ahk_exe idea64.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, D:\JetBrains\IntelliJ IDEA 2024.1.1\bin\idea64.exe
Return
!s::
ifWinExist,ahk_exe sublime_text.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, subl
Return
;alt + s 打开Everything
!e::
ifWinExist,ahk_exe Everything.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, D:\tools\Everything-1.4.1.1005.x86\Everything.exe
Return
;Alt + T 打开 Notepad++
!T::
ifWinExist,ahk_exe notepad++.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, C:\Program Files\Notepad++\notepad++.exe
Return
;Alt + C 打开 Chrome
!C::
ifWinExist,ahk_exe chrome.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, C:\Program Files\Google\Chrome\Application\chrome.exe
Return
;Window + ` 打开 命令行
#`::
RefreshEnvironment()
Run C:\Users\WIN10\AppData\Local\Microsoft\WindowsApps\wt.exe
return
;ToggleTerminal()
Return
;Alt + P 打开 Postman
!P::
ifWinExist,ahk_exe Postman.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, C:\Users\WIN10\AppData\Local\Postman\Postman.exe
Return
;Alt +Shift+ E 打开 TotalCMD64
#+E::
ifWinExist,ahk_exe TotalCMD64.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, D:\tools\TotalCMD64\TotalCMD64.exe
Return
;Alt + N 打开 Navicat for MySQL
!N::
ifWinExist,ahk_exe navicat.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, D:\navcat\Navicat Premium 15\navicat.exe
Return
;Alt + W 打开 微信
!W::
ifWinExist,ahk_exe WeChat.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, D:\WeChat3.6.0.18\WeChat\WeChat.exe
Return
;Alt + V 打开 VSCODE
!V::
ifWinExist,ahk_exe Code.exe ;;;进程是否启动
winActivate ;;; 激活窗口
else
Run, C:\Users\WIN10\AppData\Local\Programs\Microsoft VS Code\Code.exe
Return
;按下ALT + ESC ,将窗口最小化
!Escape::
send, {lwin down}{down}
sleep 50
send, {lwin up}
return
;按下ALT + ` ,将窗口最大化
!`::
send, {lwin down}{up}
sleep 50
send, {lwin up}
return
; 获取窗体 class 信息
!g::
WinGetTitle, Title, A
msgbox,%title%
clipboard=%title%
return
;idea 项目列表
+F2:: SwitchIdeProduct("idea")
;vscode 项目列表
+F3:: SwitchIdeProduct("code.exe")
; win + Ctrl + c 复制当前文件路径
^#c::
send ^c
sleep,200
clipboard=%clipboard% ;%null%
tooltip,%clipboard%
sleep,500
tooltip,
return
SwitchIdeProduct(_process_){
list := ""
Menu, windows, Add
Menu, windows, deleteAll
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
If (!IsWindow(WinExist("ahk_id" . this_ID)))
continue
WinGet, Path, ProcessPath, ahk_id %this_ID%
if(!inStr(Path,_process_))
continue
Menu, windows, Add, %title%, ActivateTitle
Try
Menu, windows, Icon, %title%, %Path%, , 0
Catch
Menu, windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
}
CoordMode, Mouse, Screen
MouseMove, (0.4*A_ScreenWidth), (0.35*A_ScreenHeight)
CoordMode, Menu, Screen
Xm := (A_ScreenWidth/2)-(Width/2)
Ym := (A_ScreenHeight/2)-(Height/2)
Menu, windows, Show, %Xm%, %Ym%
}
ActivateTitle:
SetTitleMatchMode 3
WinActivate, %A_ThisMenuItem%
return
;-----------------------------------------------------------------
; Check whether the target window is activation target
;-----------------------------------------------------------------
IsWindow(hWnd){
WinGet, dwStyle, Style, ahk_id %hWnd%
if ((dwStyle&0x08000000) || !(dwStyle&0x10000000)) {
return false
}
WinGet, dwExStyle, ExStyle, ahk_id %hWnd%
if (dwExStyle & 0x00000080) {
return falseR
}
WinGetClass, szClass, ahk_id %hWnd%
if (szClass = "TApplication") {
return false
}
return true
}
;press control+shift+r to reload
!5::
Msgbox, 是否确定重新加载当前脚本?
ifMsgBox, Yes
Reload
return
;命令窗口中实时刷新环境变量
RefreshEnvironment()
{
Path := ""
PathExt := ""
RegKeys := "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment,HKCU\Environment"
Loop, Parse, RegKeys, CSV
{
Loop, Reg, %A_LoopField%, V
{
RegRead, Value
If (A_LoopRegType == "REG_EXPAND_SZ" && !ExpandEnvironmentStrings(Value))
Continue
If (A_LoopRegName = "PATH")
Path .= Value . ";"
Else If (A_LoopRegName = "PATHEXT")
PathExt .= Value . ";"
Else
EnvSet, %A_LoopRegName%, %Value%
}
}
EnvSet, PATH, %Path%
EnvSet, PATHEXT, %PathExt%
}
ExpandEnvironmentStrings(ByRef vInputString)
{
; get the required size for the expanded string
vSizeNeeded := DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Int", 0, "Int", 0)
If (vSizeNeeded == "" || vSizeNeeded <= 0)
return False ; unable to get the size for the expanded string for some reason
vByteSize := vSizeNeeded + 1
If (A_PtrSize == 8) { ; Only 64-Bit builds of AHK_L will return 8, all others will be 4 or blank
vByteSize *= 2 ; need to expand to wide character sizes
}
VarSetCapacity(vTempValue, vByteSize, 0)
; attempt to expand the environment string
If (!DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Str", vTempValue, "Int", vSizeNeeded))
return False ; unable to expand the environment string
vInputString := vTempValue
; return success
Return True
}