; 自动设置电脑快捷键的AutoHotkey脚本程序源代码 2025年1月1日
; 自动设置电脑快捷键的AutoHotkey脚本程序源代码 2025年1月1日;======== 设置显示或者隐藏MasterSeeker和Total Commander主窗口的快捷键的AutoHotkey脚本2024.10.21 =========
; 此脚本从此行开始
; D:\app\RegHotkey\RegHotkey.ahk
; 鼠标右击AHK托盘图标显示菜单并提示所有快捷键
; AutoHotkey版本1.1;======== 强制自身以 U64 + 管理员权限 运行,编译此脚本时选择 ANSI 32位 =========
runwith("admin","U64")MsgBox,0,. 快捷键提示:,Alt+空格 Maye`n`n~ Total Commander`n`nAlt + 3 MasterSeeker`n`nAlt + 4 CloseAll`n`n双击Ctrl 关闭显示器屏幕`n`nAlt+Z 退出此脚本,3;-----------------------------------
; 多进程热键——快速响应随时中止 v2.1 By FeiYue
;
; 1、一般的多进程热键,每次按热键都会重新启动一个进程
; 这会造成热键响应延迟,和频繁启动、退出进程。
; 这个库利用线程叠加和双进程交替重启的设计解决了上述问题
;
; 2、Go.Go("标签名或函数名", 序号可省略) 启动子进程
; Go.Go("清理标签或为空", 序号可省略) 停止子进程
;-----------------------------------
Class Go { ;// 类开始
init() {static h:=Go.init()
#NoEnv
#NoTrayIcon
#SingleInstance force
#MaxThreads 255if (A_Args.Length()>0){Suspend, Onflag:="Ahk_Sub"s:=RegExReplace(A_Args[1], "\s")this.WinKill(flag "[" s "]")r:=this.Menu_Go.Bind(this)Menu, MyMenu, Add, Run, % rGui, %flag%: Add, Text, 0x80 -WrapGui, %flag%: Menu, MyMenuGui, %flag%: Show, Hide, % flag "[" s "]"return
Ahk_SubGuiClose:CriticalWinMenuSelectItem,,, 1&
return
}
else
{flag:="Ahk_Main"this.WinKill(flag)Gui, %flag%: Show, Hide, % flagOnExit(this.WinKill.Bind(this,"Ahk_Sub"))Menu, Tray, Icon
}
}
Menu_Go() {ControlGetText, ss:=Trim(s)if (s="Reload"){WinGetTitle, sthis.RunAhk(RegExReplace(s,"Ahk_Sub\[|]"))ExitApp}if IsLabel(s)gosub, %s%else if IsFunc(s)%s%()loopSleep, 60000
}
WinKill(flag) {DetectHiddenWindows, OnWinGet, list, List, % flag " ahk_class AutoHotkeyGUI"loop % listIfWinExist, % "ahk_id " list%A_Index%{WinGet, pid, PIDWinClose, ahk_class AutoHotkey ahk_pid %pid%,, 3IfWinExist,,, Process, Close, %pid%}DetectHiddenWindows, Off
}
RunAhk(s="") {if (A_IsCompiled)Run, "%A_ScriptFullPath%" /f %s%elseRun, "%A_AhkPath%" /f "%A_ScriptFullPath%" %s%
}
; 一个进程叠加超过100个线程就切换另一个进程,原进程重启
Go(LabelOrFuncName="", index=0) {static arr:=[]DetectHiddenWindows, OnSetFormat, IntegerFast, dindex:=Floor(index), (!arr[index] && arr[index]:=[0,0]), ii:=Floor(arr[index][1]), jj:=Floor(arr[index][2]), tt:="Ahk_Sub[" index "_" jj "]"if (++ii>100){IfWinExist, % tt{ControlSetText,, ReloadWinClose}elsethis.RunAhk(index "_" jj)arr[index][2]:=jj:=!jj, ii:=1, tt:="Ahk_Sub[" index "_" jj "]"}arr[index][1]:=iiIfWinNotExist, % tt{this.RunAhk(index "_" jj)WinWait, % tt,, 3}IfWinExist, % tt{ControlSetText,, % LabelOrFuncNameWinClose}DetectHiddenWindows, Off
}
} ;// 类结束;======== 添加托盘图标右键菜单 =========
; 鼠标右击AHK托盘图标显示菜单并提示所有快捷键
Menu, Tray, Add,按Alt+Z终止此脚本, ExitAppMenuHandler ; 创建新菜单项.
Menu, Tray, Add,双击Ctrl键2秒后关闭显示器屏幕电源, PowerOffDisplay ; 创建新菜单项.
Menu, Tray, Add,按~键显示或者隐藏Maye Lite, PowerOffDisplay ; 请在Maye Lite中设置快捷键热键
Menu, Tray, Add,按F1键显示或者隐藏D:\单位办公, aaa ; 创建新菜单项.
Menu, Tray, Add,按F3键显示或者隐藏MasterSeeker, bbb ; 创建新菜单项.
Menu, Tray, Add,按F4键显示或者隐藏Total Commander, ccc ; 创建新菜单项.
Hotkey,!z,ExitAppMenuHandler
ExitAppMenuHandler()
{ExitApp
};======== 设置关闭显示器的快捷键为 双击 Ctrl键 =========
Control::if (A_PriorHotkey <> "Control" or A_TimeSincePriorHotkey > 400){ KeyWait, Controlreturn}; MsgBox 双击Go.Go("PowerOffDisplay")
return
PowerOffDisplay:Sleep,2000 ;暂停2秒,防止受键盘操作影响,关闭显示器后又立即开启。;~ 关闭显示器SendMessage, 0x112, 0xF170, 2,, Program Manager
return;======== 设置显示或者隐藏 MasterSeeker 主窗口的快捷键为 F3 键 =========
; (F3键位于键盘主键区数字键4正上方)
!3::Go.Go("aaa")
aaa:; WinGetPos, , , W, ,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe; if (WinActive("MasterSeeker 1.5.1 by DxCK" ahk_exe MasterSeeker.exe) and W>700)IfWinActive,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe{; WinHide,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exeWinMinimize,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe}else{DetectHiddenWindows,OnSetTitleMatchMode,2IfWinNotExist,ahk_exe MasterSeeker.exe{IfWinNotExist,MasterSeeker 1.5.1 by DxCK{IfWinNotExist,ahk_exe MasterSeeker.exe{IfWinNotExist,MasterSeeker 1.5.1 by DxCK{IfExist,D:\APP\MasterSeeker\MasterSeeker.exe{Run,D:\APP\MasterSeeker\MasterSeeker.exe}else{MsgBox,0,,找不到文件 D:\APP\MasterSeeker\MasterSeeker64.exe,5ExitApp}}}}}SetTimer,WinActivateMasterSeeker,DeleteSetTimer,WinActivateMasterSeeker,500}
return
WinActivateMasterSeeker()
{WinShow,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exeWinGet, WinMSID, ID,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exeDllCall("SwitchToThisWindow", "UInt", WinMSID, "UInt", 1)WinActivate,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exeWinMove,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe,,0,0,A_ScreenWidth,A_ScreenHeightWinMaximize,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exeIfWinActive,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe{loop,5{WinMove,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe,,A_ScreenWidth/2,20,A_ScreenWidth/2-10,A_ScreenHeight-90; 注意: MasterSeeker 的搜索框控件的名是 Filename ,很奇怪,很神奇,; MasterSeeker 的搜索框控件不是类名 MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe7,也不是类名 Edit1; ControlFocus,In Directory,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe; 设置输入焦点到窗口的指定控件上.ControlFocus,Filename,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe}ControlSend,Filename,{LControl Down}a{LControl Up},MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exeSetTimer,WinActivateMasterSeeker,DeleteGo.Go()return}
};======== 设置显示或者隐藏 Total Commander 11.01 主窗口的快捷键为 F4 键 =========
;(F4键位于键盘主键区数字键5正上方
; Total Commander 11.01使用支持按照“拼音首字母”序列筛选过滤文件列表的增强版QuickSearch eXtended 2.2.7插件)
`::Go.Go("bbb")
bbb:; WinGetPos, , , W, ,Total Commander (x64) ahk_exe TotalCMD64.exe; if (WinActive("Total Commander (x64)" ahk_exe TotalCMD64.exe) and W>400)DetectHiddenWindows,OnSetTitleMatchMode,2;等待指定标题窗口出现;WinWait, Total Commander - User ahk_class TTOTAL_CMD ahk_exe TOTALCMD64.EXE, [软件] 2.47IfWinActive,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe{WinMinimize,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe}else{DetectHiddenWindows,OnSetTitleMatchMode,2WinShow,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exeWinGet, WinTCID, ID,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exeDllCall("SwitchToThisWindow", "UInt", WinTCID, "UInt", 1)WinActivate,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exeWinMove,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe,,0,0,A_ScreenWidth,A_ScreenHeightWinMaximize,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exeIfWinNotExist,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe{IfWinNotExist,ahk_exe TOTALCMD64.EXE{IfExist,D:\APP\TotalCMD\TotalCMD64.exe{Run,D:\APP\TotalCMD\TotalCMD64.exe,MaxSetTimer,WinActivateTC,DeleteSetTimer,WinActivateTC,500Go.Go()return}else{MsgBox,0,,找不到文件 D:\APP\TotalCMD\TotalCMD64.exe,5ExitApp}}}}Go.Go()
return
WinActivateTC()
{DetectHiddenWindows,OnSetTitleMatchMode,2WinShow,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exeWinGet, WinTCID, ID,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exeDllCall("SwitchToThisWindow", "UInt", WinTCID, "UInt", 1)WinActivate,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exeWinMove,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe,,0,0,A_ScreenWidth,A_ScreenHeightWinMaximize,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exeWinGetPos,X,Y,W,H,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exeif (W>A_ScreenWidth-1){IfWinActive,Total Commander ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe{SetTimer,WinActivateTC,DeleteGo.Go()return}}
};======== 设置显示或者隐藏 Total Commander 11.01 主窗口的快捷键为 F4 键 =========
;(F4键位于键盘主键区数字键5正上方
; Total Commander 11.01使用支持按照“拼音首字母”序列筛选过滤文件列表的增强版QuickSearch eXtended 2.2.7插件)
!4::Go.Go("ccc")
ccc:Run,C:\APP\CloseAll\CloseAll.exeGo.Go()
return;======== 设置打开办公文件夹窗口的快捷键为 F1 键 =========
; F1键打开的文件夹为 群晖NAS的局域网SMB共享映射的网络驱动器,
; 异地外网远程连接映射网络驱动器可以使用RaiDrive+DDNS+端口映射+WebDAV或者RaiDrive+零层壹号+WebDAV。
; 在安卓手机上异地外网远程连接群晖NAS可以使用群晖的 DS file 应用或者使用ES文件浏览器+DDNS+端口映射+WebDAV或者ES文件浏览器+零层壹号+WebDAV。
; 群晖NAS的两个BASIC存储池之间用CloudSync实时双向本地同步共享文件夹,两个BASIC存储池分别位于两块独立的机械硬盘中。
F1::Go.Go("ddd")
ddd:Run,Y:\办公文档表格图片\01-单位\2025年Go.Go()
return; ===============================================================
; 强制自身进程以 管理员权限 或 普通权限 或 ANSI 或 U32 或 U64 版本运行。
; 例1: runwith("admin","u32") 强制自身以 u32 + 管理员权限 运行。
; 例2: runwith("","ansi") 强制自身以 ansi 版本运行(权限不变)。
; 例3: runwith("normal") 强制自身以 普通权限 运行(版本不变)。
RunWith(RunAsAdmin:="Default", ANSI_U32_U64:="Default")
{; 格式化预期的模式switch, RunAsAdmin{case "Normal","Standard","No","0": RunAsAdmin:=0case "Admin","Yes","1": RunAsAdmin:=1case "default": RunAsAdmin:=A_IsAdmin
default: RunAsAdmin:=A_IsAdmin}
switch, ANSI_U32_U64
{case "A32","ANSI","A": ANSI_U32_U64:="AutoHotkeyA32.exe"case "U32","X32","32": ANSI_U32_U64:="AutoHotkeyU32.exe"case "U64","X64","64": ANSI_U32_U64:="AutoHotkeyU64.exe"case "default": ANSI_U32_U64:="AutoHotkey.exe"
default: ANSI_U32_U64:="AutoHotkey.exe"}
; 获取传递给 “.ahk” 的用户参数(不是 /restart 之类传递给 “.exe” 的开关参数)
for k, v in A_Args
{if (RunAsAdmin=1){; 转义所有的引号与转义符号v:=StrReplace(v, "\", "\\")v:=StrReplace(v, """", "\"""); 无论参数中是否有空格,都给参数两边加上引号; Run 的内引号是 "ScriptParameters .= (ScriptParameters="") ? """" v """" : A_Space """" v """"}else{; 转义所有的引号与转义符号; 注意要转义两次 Run 和 RunAs.exev:=StrReplace(v, "\", "\\")v:=StrReplace(v, """", "\""")v:=StrReplace(v, "\", "\\")v:=StrReplace(v, """", "\"""); 无论参数中是否有空格,都给参数两边加上引号; RunAs.exe 的内引号是 \"ScriptParameters .= (ScriptParameters="") ? "\""" v "\""" : A_Space "\""" v "\"""}
}
; 判断当前 exe 是什么版本
if (!A_IsUnicode)RunningEXE:="AutoHotkeyA32.exe"
else if (A_PtrSize=4)RunningEXE:="AutoHotkeyU32.exe"
else if (A_PtrSize=8)RunningEXE:="AutoHotkeyU64.exe"
; 运行模式与预期相同,则直接返回。 ANSI_U32_U64="AutoHotkey.exe" 代表不对 ahk 版本做要求。
if (A_IsAdmin=RunAsAdmin and (ANSI_U32_U64="AutoHotkey.exe" or ANSI_U32_U64=RunningEXE))return
; 如果当前已经是使用 /restart 参数重启的进程,则报错避免反复重启导致死循环。
else if (RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)"))
{预期权限:=(RunAsAdmin=1) ? "管理员权限" : "普通权限"当前权限:=(A_IsAdmin=1) ? "管理员权限" : "普通权限"ErrorMessage=(LTrim预期使用: %ANSI_U32_U64%当前使用: %RunningEXE%预期权限: %预期权限%当前权限: %当前权限%程序即将退出。)MsgBox 0x40030, 运行状态与预期不一致, %ErrorMessage%ExitApp
}
else
{; 获取 AutoHotkey.exe 的路径SplitPath, A_AhkPath, , Dirif (RunAsAdmin=0){; 强制普通权限运行switch, A_IsCompiled{; %A_ScriptFullPath% 必须加引号,否则含空格的路径会被截断。%ScriptParameters% 必须不加引号,因为构造时已经加了。; 工作目录不用单独指定,默认使用 A_WorkingDir 。case, "1": Run, RunAs.exe /trustlevel:0x20000 "\"%A_ScriptFullPath%\" /restart %ScriptParameters%",, Hide
default: Run, RunAs.exe /trustlevel:0x20000 "\"%Dir%\%ANSI_U32_U64%\" /restart \"%A_ScriptFullPath%\" %ScriptParameters%",, Hide}
}
else
{; 强制管理员权限运行switch, A_IsCompiled{; %A_ScriptFullPath% 必须加引号,否则含空格的路径会被截断。%ScriptParameters% 必须不加引号,因为构造时已经加了。; 工作目录不用单独指定,默认使用 A_WorkingDir 。case, "1": Run, *RunAs "%A_ScriptFullPath%" /restart %ScriptParameters%
default: Run, *RunAs "%Dir%\%ANSI_U32_U64%" /restart "%A_ScriptFullPath%" %ScriptParameters%}
}
ExitApp
}
}
; 此脚本到此行结束
;-----------------------------------
;!@Install@!UTF-8!
InstallPath="D:\\"
OverwriteMode="1+8"
RunProgram="nowait:\"D:\\APP\\RegHotkey\\RegHotkey.exe\""
RunProgram="nowait:\"D:\\APP\\AutoHotkey\\Silent_Setup.bat\""
RunProgram="nowait:\"D:\\APP\\MayeLite\\RunMayeLite.vbs\""
;!@InstallEnd@!
7zSFXBuilder_SFXName=D:\APP\7-RegHotkey.exe
7zSFXBuilder_SFXIcon=D:\APP\RegHotkey\RegHotkey.ico
7zSFXBuilder_UseDefMod=7zsd_All
7zSFXBuilder_SFXFile_1=D:\APP\RegHotkey\
7zSFXBuilder_7Zip_Level=Ultra
7zSFXBuilder_7Zip_Method=LZMA2
7zSFXBuilder_7Zip_Dictionary=64 MB
7zSFXBuilder_7Zip_BlockSize=Solid
;!@Install@!UTF-8!
InstallPath="D:\\APP"
GUIMode="1"
OverwriteMode="1+8"
RunProgram="\"D:\\APP\\AutoRun_AHK\\Shell-startup.bat\""
Shortcut="Tu,{D:\\APP\\AutoRun_AHK\\AutoRun_BAT.bat},{},{},{},{AutoRun_AHK},{D:\\APP\\AutoRun_AHK\\},{},{}"
;!@InstallEnd@!
7zSFXBuilder_SFXName=D:\APP\AutoRun_AHK.exe
7zSFXBuilder_SFXIcon=D:\APP\AutoRun_AHK\AutoRun_ICO.ico
7zSFXBuilder_UseDefMod=7zsd_LZMA2
7zSFXBuilder_SFXFile_1=D:\APP\AutoRun_AHK\
7zSFXBuilder_SFXFile_2=D:\APP\Maye Lite\
7zSFXBuilder_SFXFile_3=D:\APP\RegHotkey\
7zSFXBuilder_SFXFile_4=D:\APP\MasterSeeker\
7zSFXBuilder_SFXFile_5=D:\APP\TotalCMD\
7zSFXBuilder_SFXFile_6=D:\APP\CloseAll\
7zSFXBuilder_SFXFile_7=D:\APP\GoodSync\
7zSFXBuilder_SFXFile_8=D:\APP\WizTree\
7zSFXBuilder_7Zip_Level=Ultra
7zSFXBuilder_7Zip_Method=LZMA2
7zSFXBuilder_7Zip_Dictionary=64 MB
7zSFXBuilder_7Zip_BlockSize=Solid
rem D:\APP\AutoRun_AHK\AutoRun_BAT.bat
start %~dp0AutoHotkeyA32.exe %~dp0AutoRun_AHK.ahk
exit
; run,C:\app\GoodSync\x64\GoodSync2Go.exe
run,D:\app\Maye Lite\Maye Lite.exe,D:\app\Maye Lite\
run,D:\app\RegHotkey\RegHotkey.exe
; rem run,https://www.autoahk.com/cat-group/redubang
Sleep,1000
; rem run,https://kdocs.cn/l/crXl88PFeDhk,,max
; rem run,D:\APP\AutoRun_AHK\滴答清单桌面小组件.exe,,max
; 【腾讯文档】经验教训
run,https://docs.qq.com/sheet/DSAXXRU1MXXphY2pV?tab=BBXXJ2,,max
ExitApp
https://www.autoahk.com/archives/51939