方案0:简单4行代码搞定。
#f::
SendMessage 1074, 21, 0, , ahk_class TTOTAL_CMD
ControlGetText, varPathInTC, , ahk_id %ErrorLevel%
StringReplace, varPathInTC, varPathInTC, >, "\ "
run "D:\Everything\Everything.exe" -search %varPathInTC%
return
;注释:
; MsgBox curdirpanel_id: %ErrorLevel% ; e.g.: 7014276
;(The controls' current ID, a random number, valid for the time being, will change on next situation)
;参考 :https://ghisler.ch/board/viewtopic.php?t=44451
;AHK-L v1.1.22.09:
;ControlGetText, OutputVar [, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
;To operate upon a control's HWND (window handle),
;leave the Control parameter blank
;and specify <<<ahk_id %ControlHwnd%>>> for the WinTitle parameter
方案1:
2011年我在 https://www.ghisler.ch/wiki/index.php?title=AutoHotkey:_Send_a_user_command_to_Total_Commander
发布的一个方案,当时的方案不支持Unicode,现在完善下(TC官网wiki的登录密码,我忘记了重置邮件又收不到,暂时没法更新到wiki上)。
先要在TC中定义自定义命令em_Everything,然后向TC发送消息去调用自定义命令。
可以直接在usercmd.ini文件中定义em_Everything的:
[em_Everything]
button=D:\Everything\Everything.exe
cmd=D:\Everything\Everything.exe
param=-search "%P "
path=D:\Everything\
menu=搜索当前目录
也可以如下图示,创建em_Everything:
#z::
TC_SendData("em_Everything") ; User Command
return
TC_SendData(Cmd) {
VarSetCapacity(CopyDataStruct, A_PtrSize * 3)
If( A_IsUnicode ) {
VarSetCapacity( cmdU, StrPut(cmd, "cp0"),0)
Loop, % StrLen(cmd)
NumPut( Asc(SubStr(cmd, A_Index, 1)), cmdU, A_Index - 1, "Char")
}
NumPut(Asc("E") + 256 * Asc("M"), CopyDataStruct,0 )
NumPut( StrLen(cmd), CopyDataStruct, A_PtrSize )
NumPut((A_IsUnicode ? &cmdU : &cmd), CopyDataStruct, A_PtrSize * 2)
SendMessage, 0x4A,%A_ScriptHwnd%, &CopyDataStruct,, ahk_class TTOTAL_CMD
}