Select Filename in TC7 using AHK

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

User avatar
majkinetor !
Power Member
Power Member
Posts: 1580
Joined: 2006-01-18, 07:56 UTC
Contact:

Select Filename in TC7 using AHK

Post by *majkinetor ! »

This is result of cooperation of icfu and me on AHK forum :)

To test it open the TC and execute the script. Press ALT M to open input box. Type a file name in any panel to select it.


Code: Select all

!m::
    InputBox fn, ,type a file name to select
    if errorlevel != 1
        if !SetTCFileName(fn, "right", 1)
            SetTCFileName(fn, "left", 1)
return

;-------------------------------------------------------------------- 
; PURPOSE: Set the focus to given file name
; 
; ARGS:   
;       FN          - file name to set 
;       panel       - panel in witch file resides (1=right=default, 2=left) 
;       select      - true to select, false=default 
; 
SetTCFileName( fn, panel="", select=false ) 
{ 
    static sss, LB_SETCARETINDEX, LB_GETTEXT
    
    ;initialise
    if LB_SETCARETINDEX=
    { 
        LB_SETCARETINDEX    = 0x19E 
        LB_GETTEXT          = 0x189 
        VarSetCapacity(sss, 512) 
    } 

    ;check active TC panel
    GetTCPanels( pLeft, pRight)
    cur := GetCurrentTCDir()

    if (cur = pLeft)
        if (panel = "right")
           ControlSend, TMyListBox2, {TAB}, ahk_class TTOTAL_CMD 
    
    if (cur = pRight)
        if (panel = "left")
            ControlSend, TMyListBox1, {TAB}, ahk_class TTOTAL_CMD 


    if (panel = "right") or (panel="")
            panel = TMyListBox1
    else    panel = TMyListBox2
    
    loop 
    { 
        SendMessage LB_GETTEXT, A_Index, &sss,          %panel%, ahk_class TTOTAL_CMD 
        if sss=
            return 0

        if (sss = fn)
        { 
            SendMessage LB_GETTEXT, A_Index+1, &sss,    %panel%, ahk_class TTOTAL_CMD 
            SendMessage, LB_SETCARETINDEX, A_Index, 1,  %panel%, ahk_class TTOTAL_CMD       

            break 
        } 
    } 
    
    if (select) 
    {
       ControlSend, %panel%, {INSERT}, ahk_class TTOTAL_CMD 
       if sss != 
            ControlSend, %panel%, {UP}, ahk_class TTOTAL_CMD 
    }

    return 1
}

;--------------------------------------------------------------------------
; set left and right panel and return source
;
GetTCPanels( ByRef pLeft, ByRef pRight)
{

    ControlGetText pLeft,  TMyPanel5, ahk_class TTOTAL_CMD
    ControlGetText pRight, TMyPanel9, ahk_class TTOTAL_CMD

    StringReplace pLeft, pLeft, \*.*
    StringReplace pRight, pRight, \*.*
}

;--------------------------------------------------------------------------

GetCurrentTCDir()
{
    ControlGetText src, TMyPanel2, ahk_class TTOTAL_CMD
    StringReplace src, src, >
    return src
}
Last edited by majkinetor ! on 2006-11-14, 08:56 UTC, edited 5 times in total.
Habemus majkam!
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

Absolutely brilliant!
THANKS!
I switched to Linux, bye and thanks for all the fish!
TucknDar
Senior Member
Senior Member
Posts: 227
Joined: 2003-02-07, 09:44 UTC
Location: Oslo
Contact:

Post by *TucknDar »

I must be thick as a board, but I can't get this to work...? I'm on Win2k, and switched the "Windows" text to "Winnt" but it doesn't do anything (correction: It activates TC, but doesn't do anything more). Any hints welcome, as it's probably just some error between chair and keyboard :p
license #76904
User avatar
robinsiebler
Senior Member
Senior Member
Posts: 460
Joined: 2003-03-05, 21:04 UTC

Post by *robinsiebler »

That rocks! I wish AutoIT and AHK would merge so I could do stuff like that in AutoIT. :(
Robin L. Siebler
Personal License #13949
------------------------------
"Bother", said Pooh, as he deleted Windows
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

2TucknDar
It works only in the left panel, and in c:\
Ah and make sure you have the latest AutoHotkey version, lots have changed lately...
I switched to Linux, bye and thanks for all the fish!
User avatar
StickyNomad
Power Member
Power Member
Posts: 1933
Joined: 2004-01-10, 00:15 UTC
Location: Germany

Post by *StickyNomad »

2TucknDar
It activates TC, but doesn't do anything more
Hm, if TC 'gets activated' after the script is run, I assume you did run the script _not_ from within TC?

I strongly assume this script will only work if started directly in TC.

EDIT
2Sans: Hm, too fast for me (and more exact) :)
/EDIT
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

Send {INSERT}{UP}
Of course this is not the final version, as this gives wrong result on the last file in the list.
I switched to Linux, bye and thanks for all the fish!
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

I strongly assume this script will only work if started directly in TC.
Not true. One more problem might be this line:

Code: Select all

   WInActivate Total
better use this:

Code: Select all

WinActivate ahk_class TTOTAL_CMD
I switched to Linux, bye and thanks for all the fish!
TucknDar
Senior Member
Senior Member
Posts: 227
Joined: 2003-02-07, 09:44 UTC
Location: Oslo
Contact:

Post by *TucknDar »

I start it from within TC, yes, and with latest version. I'll see if I've made mods to default TC stuff that the script depends on...
license #76904
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

2TucknDar
How do you start it from within TC? Toolbar? or is the ahk file in the root in the left panel?
I switched to Linux, bye and thanks for all the fish!
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

I wish AutoIT and AHK would merge so I could do stuff like that in AutoIT.
Well, AutoIT has had its chance some time ago. As a result of that forgiven chance, AHK was born with excellent hotkey handling, hotstrings and much better speed. ;)

Now we have two different languages and I think it's ok like that. A merging of these two would result in a loss meanwhile, for both parties.

What prevents you from doing this example in AutoIt?

Icfu
This account is for sale
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

True, AutoIt3 absolutely supports all that in this script. Send message is done by a dll call.
I switched to Linux, bye and thanks for all the fish!
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

AutoIt has even included a wrapper meanwhile:

Code: Select all

Wrapper for commonly used Dll Call
#Include <SendMessage.au3>
_SendMessage(hWnd, msg[, wParam = 0[, lParam = 0[, return = 0[, wParam Type = "int"[, lParam Type = "int"]]]]])
Icfu
This account is for sale
TucknDar
Senior Member
Senior Member
Posts: 227
Joined: 2003-02-07, 09:44 UTC
Location: Oslo
Contact:

Post by *TucknDar »

SanskritFritz wrote:2TucknDar
How do you start it from within TC? Toolbar? or is the ahk file in the root in the left panel?
I've tried button, ahk in root, ahk in my regular script dir, and launched the ahk file from outside TC.
license #76904
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

2TucknDar
Wow. Detailed scenario please.
I switched to Linux, bye and thanks for all the fish!
Post Reply