AutoHotkey: Send a user command to Total Commander

From TotalcmdWiki
Jump to navigation Jump to search
; Script Name: SendTCUserCommand.ahk
; AutoHotkey : 1.1.2.3 ansi
; Operating System: Windows XP
; Author:        sunwind <1576157@qq.com> 
; Blog:        http://blog.csdn.net/liuyukuan
; Function:Send a user command to Total Commander
; Version:   v1.01


; Total Commander 《usercmd.ini》 defined function as follow:
; [em_openDefaultTab]
; cmd=OPENTABS %COMMANDER_PATH%\tab\!!!.tab
#1::  ;TEST
  SendTCUserCommand("em_openDefaultTab")
Return
SendTCUserCommand(Command) ; string
  {
    If  Command <>
      {
        VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)  ; Set up the structure's memory area.
        dwData := Asc("E") + 256 * Asc("M")
        NumPut(dwData,  CopyDataStruct, 0)
        cbData := (StrLen(Command) + 1) * (A_IsUnicode ? 2 : 1)  ;SizeInBytes
        NumPut(cbData, CopyDataStruct, A_PtrSize)  ; OS requires that this be done.
        NumPut(&Command, CopyDataStruct, 2*A_PtrSize)  ; 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.
      }
  }

Back to AutoHotkey