如何用AHK_V2 发送用户命令给Total Commander【已解决】

尝试着将这个 脚本转化成了ahk_v2 版,但没有产生任何效果。
请坛子里的高手帮忙诊断下,谢谢。

F1::
{
    SendTCUserCommand("em_savealltabs")
}
SendTCUserCommand(Command) 
{
    ; https://www.ghisler.ch/wiki/index.php?title=AutoHotkey:_Send_a_user_command_to_Total_Commander
    If  (Command !="")
    {
        CopyDataStruct:= Buffer(3*A_PtrSize)  ; Set up the structure's memory area.
        dwData := Ord("E") + 256 * Ord("M")
        NumPut("Ptr", dwData, CopyDataStruct, 0)
        cbData := (StrLen(Command) + 1) *2   ;SizeInBytes
        NumPut( "UInt",cbData, CopyDataStruct, A_PtrSize)  ; OS requires that this be done.
        NumPut("Ptr", StrPtr(Command), CopyDataStruct,  A_PtrSize * 2 ) ; Set lpData to point to the string itself.
        SendMessage( 0x4a, 0, CopyDataStruct,, "ahk_class TTOTAL_CMD") ; 0x4a is WM_COPYDATA. Must use Send not Post.    }
    }
}

user.ini 中的配置

[em_savealltabs]
button=wcmicons.dll,10
cmd=SAVETABS2
param=%COMMANDER_PATH%\SAVETABS2.tab

TC_SendUserCommand(userCommand) 
{
    ; https://www.autohotkey.com/boards/viewtopic.php?p=538463&sid=4471e03917209854441ac07ebdc70901#p538463
    static dwData := 19781  ;Ord("E") +256*Ord("M")
    static WM_COPYDATA := 0x4A
    cbData := Buffer(StrPut(userCommand, 'CP0'))
    StrPut(userCommand, cbData, 'CP0')
    COPYDATASTRUCT := Buffer(A_PtrSize * 3)
    NumPut('Ptr', dwData, 'Ptr', cbData.size, 'Ptr', cbData.ptr, COPYDATASTRUCT)
    MsgResult:=SendMessage( WM_COPYDATA,, COPYDATASTRUCT,, 'ahk_class TTOTAL_CMD')
    return MsgResult
}

自己搞定了?

一顿魔改,搞定了。
可以用autohotkey V2 调用TC usercmd.ini中定义的命令了。 :grinning: