设置显示或者隐藏MasterSeeker和Total Commander主窗口的快捷键的AutoHotkey脚本2024.10.21 =========
;======== 设置显示或者隐藏MasterSeeker和Total Commander主窗口的快捷键的AutoHotkey脚本2024.10.21 =========
; 此脚本从此行开始
; D:\app\RegHotkey\RegHotkey.ahk
; 鼠标右击AHK托盘图标显示菜单并提示所有快捷键
; AutoHotkey版本1.1
;======== 强制自身以 ansi + 管理员权限 运行,编译此脚本时选择 ANSI 32位 =========
runwith("admin","ansi")
;-----------------------------------
; 多进程热键——快速响应随时中止 v2.1 By FeiYue
;
; 1、一般的多进程热键,每次按热键都会重新启动一个进程
; 这会造成热键响应延迟,和频繁启动、退出进程。
; 这个库利用线程叠加和双进程交替重启的设计解决了上述问题
;
; 2、Go.Go("标签名或函数名", 序号可省略) 启动子进程
; Go.Go("清理标签或为空", 序号可省略) 停止子进程
;-----------------------------------
Class Go { ;// 类开始
init() {
static h:=Go.init()
#NoEnv
#NoTrayIcon
#SingleInstance force
#MaxThreads 255
if (A_Args.Length()>0)
{
Suspend, On
flag:="Ahk_Sub"
s:=RegExReplace(A_Args[1], "\s")
this.WinKill(flag "[" s "]")
r:=this.Menu_Go.Bind(this)
Menu, MyMenu, Add, Run, % r
Gui, %flag%: Add, Text, 0x80 -Wrap
Gui, %flag%: Menu, MyMenu
Gui, %flag%: Show, Hide, % flag "[" s "]"
return
Ahk_SubGuiClose:
Critical
WinMenuSelectItem,,, 1&
return
}
else
{
flag:="Ahk_Main"
this.WinKill(flag)
Gui, %flag%: Show, Hide, % flag
OnExit(this.WinKill.Bind(this,"Ahk_Sub"))
Menu, Tray, Icon
}
}
Menu_Go() {
ControlGetText, s
s:=Trim(s)
if (s="Reload")
{
WinGetTitle, s
this.RunAhk(RegExReplace(s,"Ahk_Sub\[|]"))
ExitApp
}
if IsLabel(s)
gosub, %s%
else if IsFunc(s)
%s%()
loop
Sleep, 60000
}
WinKill(flag) {
DetectHiddenWindows, On
WinGet, list, List, % flag " ahk_class AutoHotkeyGUI"
loop % list
IfWinExist, % "ahk_id " list%A_Index%
{
WinGet, pid, PID
WinClose, ahk_class AutoHotkey ahk_pid %pid%,, 3
IfWinExist,,, Process, Close, %pid%
}
DetectHiddenWindows, Off
}
RunAhk(s="") {
if (A_IsCompiled)
Run, "%A_ScriptFullPath%" /f %s%
else
Run, "%A_AhkPath%" /f "%A_ScriptFullPath%" %s%
}
; 一个进程叠加超过100个线程就切换另一个进程,原进程重启
Go(LabelOrFuncName="", index=0) {
static arr:=[]
DetectHiddenWindows, On
SetFormat, IntegerFast, d
index:=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,, Reload
WinClose
}
else
this.RunAhk(index "_" jj)
arr[index][2]:=jj:=!jj, ii:=1
, tt:="Ahk_Sub[" index "_" jj "]"
}
arr[index][1]:=ii
IfWinNotExist, % tt
{
this.RunAhk(index "_" jj)
WinWait, % tt,, 3
}
IfWinExist, % tt
{
ControlSetText,, % LabelOrFuncName
WinClose
}
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,按F3键显示或者隐藏MasterSeeker, ccc ; 创建新菜单项.
Menu, Tray, Add,按F4键显示或者隐藏Total Commander, aaa ; 创建新菜单项.
Hotkey,!z,ExitAppMenuHandler
ExitAppMenuHandler()
{
ExitApp
}
;======== 设置关闭显示器的快捷键为 双击 Ctrl键 =========
Control::
if (A_PriorHotkey <> "Control" or A_TimeSincePriorHotkey > 400)
{ KeyWait, Control
return
}
; MsgBox 双击
Go.Go("PowerOffDisplay")
return
PowerOffDisplay:
Sleep,2000 ;暂停2秒,防止受键盘操作影响,关闭显示器后又立即开启。
;~ 关闭显示器
SendMessage, 0x112, 0xF170, 2,, Program Manager
return
;======== 设置显示或者隐藏 MasterSeeker 主窗口的快捷键为 F3 键 =========
; (F3键位于键盘主键区数字键4正上方)
F3::Go.Go("ccc")
ccc:
; 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.exe
WinMinimize,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe
}
else
{
DetectHiddenWindows,On
SetTitleMatchMode,2
IfWinNotExist,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:\Prog\MasterSeeker\MasterSeeker.exe
{
Run,D:\Prog\MasterSeeker\MasterSeeker.exe
}
else
{
MsgBox,0,,找不到文件 D:\Prog\MasterSeeker\MasterSeeker64.exe,5
ExitApp
}
}
}
}
}
SetTimer,WinActivateMasterSeeker,Delete
SetTimer,WinActivateMasterSeeker,500
}
return
WinActivateMasterSeeker()
{
WinShow,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe
WinGet, WinMSID, ID,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe
DllCall("SwitchToThisWindow", "UInt", WinMSID, "UInt", 1)
WinActivate,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe
WinMove,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe,,0,0,A_ScreenWidth,A_ScreenHeight
WinMaximize,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe
IfWinActive,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.exe
SetTimer,WinActivateMasterSeeker,Delete
Go.Go()
return
}
}
;======== 设置显示或者隐藏 Total Commander 11.01 主窗口的快捷键为 F4 键 =========
;(F4键位于键盘主键区数字键5正上方
; Total Commander 11.01使用支持按照“拼音首字母”序列筛选过滤文件列表的增强版QuickSearch eXtended 2.2.7插件)
F4::Go.Go("aaa")
aaa:
; WinGetPos, , , W, ,Total Commander (x64) ahk_exe TotalCMD64.exe
; if (WinActive("Total Commander (x64)" ahk_exe TotalCMD64.exe) and W>400)
DetectHiddenWindows,On
SetTitleMatchMode,2
;等待指定标题窗口出现
;WinWait, Total Commander (x64) 11.01 - User ahk_class TTOTAL_CMD ahk_exe TOTALCMD64.EXE, [软件] 2.47
IfWinActive,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
{
WinMinimize,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
}
else
{
WinShow,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
WinGet, WinTCID, ID,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
DllCall("SwitchToThisWindow", "UInt", WinTCID, "UInt", 1)
WinActivate,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
WinMove,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe,,0,0,A_ScreenWidth,A_ScreenHeight
WinMaximize,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
IfWinNotExist,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
{
IfWinNotExist,ahk_exe TOTALCMD64.EXE
{
IfExist,D:\Prog\TotalCMD\TotalCMD64.exe
{
Run,D:\Prog\TotalCMD\TotalCMD64.exe
Go.Go()
return
}
else
{
MsgBox,0,,找不到文件 D:\Prog\TotalCMD\TotalCMD64.exe,5
ExitApp
}
}
SetTimer,WinActivateTC,Delete
SetTimer,WinActivateTC,500
}
}
Go.Go()
return
WinActivateTC()
{
WinShow,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
WinGet, WinTCID, ID,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
DllCall("SwitchToThisWindow", "UInt", WinTCID, "UInt", 1)
WinActivate,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
WinMove,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe,,0,0,A_ScreenWidth,A_ScreenHeight
WinMaximize,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
IfWinActive,Total Commander (x64) 11.01 ahk_class TTOTAL_CMD ahk_exe TotalCMD64.exe
{
SetTimer,WinActivateTC,Delete
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:=0
case "Admin","Yes","1": RunAsAdmin:=1
case "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.exe
v:=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, , Dir
if (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
}
}
; 此脚本到此行结束
;-----------------------------------
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。