AutoHotkey Community

It is currently May 27th, 2012, 9:50 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 2nd, 2006, 4:27 pm 
Offline

Joined: February 17th, 2005, 10:06 am
Posts: 280
Location: Hungary, Budapest
Please help me. I have written a script to select a file in Total Commander, from Locate . Here is the working script:
Code:
 ;Ctrl-F (Locate: finds selected file in TC)
 $^f::
    ;This works only with the english localization of Locate
    If not WinActive( "Locate", "Presets" )
    {
       Send ^f
       Return
    }
 
    sFileName := ""
    sPath := ""
    ControlGet sActiveRow, LIST, SELECTED, SysListView321
    StringSplit aRowElements, sActiveRow, %A_Tab%
    sFileName := aRowElements1
    sPath := aRowElements2
 
    if (sFileName != "")
    {
       Run "%COMMANDER_PATH%\Totalcmd.exe" /O /T "%sPath%"
       WinWaitActive ahk_class TTOTAL_CMD
 
       PostMessage 1075, 2915 ;call quicksearch box
       WinWaitActive ahk_class TQUICKSEARCH
       ControlSetText TTabEdit1, %sFileName%
       ControlSend TTabEdit1, {Down}{Esc}
    }
    Return


Now. I love that new #IfWinActive feature of AutoHotkey, so I rewrote the script like this:
Code:
;Ctrl-F (Locate: finds selected file in TC)
;This works only with the english localization of Locate
#IfWinActive Locate, Presets
^f::
   sFileName := ""
   sPath := ""
   ControlGet sActiveRow, LIST, SELECTED, SysListView321
   StringSplit aRowElements, sActiveRow, %A_Tab%
   sFileName := aRowElements1
   sPath := aRowElements2
   MsgBox %sActiveRow%

   if (sFileName != "")
   {
      Run "%COMMANDER_PATH%\Totalcmd.exe" /O /T "%sPath%"
      WinWaitActive ahk_class TTOTAL_CMD

      PostMessage 1075, 2915 ;call quicksearch box
      WinWaitActive ahk_class TQUICKSEARCH
      ControlSetText TTabEdit1, %sFileName%
      ControlSend TTabEdit1, {Down}{Esc}
   }
   Return

The problem with this is, that now the script cannot read the SysListView321 anymore (see the MsgBox), and Locate crashes after a while. What is wrong? I have to mention, that Locate features keyboard remapping, so I suspect a collision between AutoHotkey and Locate. Or did I miss something obvious here?

_________________
Is there another word for synonym?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 3rd, 2006, 3:38 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
SanskritFritz wrote:
[with #IfWinActive present] the script cannot read the SysListView321 anymore
I can't think of any reason for that.

Quote:
...Locate crashes after a while.
...Locate features keyboard remapping, so I suspect a collision between AutoHotkey and Locate.
#IfWinActive's hotkeys use the keyboard hook (except joystick and mouse hotkeys), so maybe that's the crucial difference that causes the conflict. Perhaps in this case, it's best to go back to using the old version of the script.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 3rd, 2006, 9:41 am 
Offline

Joined: February 17th, 2005, 10:06 am
Posts: 280
Location: Hungary, Budapest
Thanks for your answer!
Chris wrote:
SanskritFritz wrote:
[with #IfWinActive present] the script cannot read the SysListView321 anymore
I can't think of any reason for that.
I think it happens because Locate crashes anyway, so there is no healthy control to read from.

Chris wrote:
#IfWinActive's hotkeys use the keyboard hook (except joystick and mouse hotkeys), so maybe that's the crucial difference that causes the conflict. Perhaps in this case, it's best to go back to using the old version of the script.
Do you think I should report this problem to the makers of Locate? Maybe there is a nonstandard implementation of hotkeys? (Locate can define local and global hotkeys)

_________________
Is there another word for synonym?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 3rd, 2006, 11:33 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Quote:
Do you think I should report this problem to the makers of Locate?
It wouldn't hurt, especially since I'm unaware of any other apps that have such problems with hook scripts. But this assumes it's really the hook and not merely a coincidence pointing to something more subtle.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2006, 11:56 am 
Offline

Joined: February 17th, 2005, 10:06 am
Posts: 280
Location: Hungary, Budapest
I tried to reproduce the problem so I can send the crash message to the authors, now Locate does not crash, but AutoHotkey is still unable to get the contents of the control with the second script!

_________________
Is there another word for synonym?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2006, 4:16 pm 
Offline

Joined: July 24th, 2005, 4:29 am
Posts: 27
Location: Rheinland
You have omitted something, so there is neither a problem with AHK nor with Locate (besides crashing, but this is due to the new daily build I think, maybe it conflicts with CLCL...). ;)

Code:
ControlGet sActiveRow, LIST, SELECTED, SysListView321, A


Icfu


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2006, 5:07 pm 
Offline

Joined: February 17th, 2005, 10:06 am
Posts: 280
Location: Hungary, Budapest
Thanks Icfu! I forgot (or rather didnt know) that the #IfWinActive directive does not fill the last found window.

_________________
Is there another word for synonym?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2006, 5:30 pm 
Offline

Joined: July 24th, 2005, 4:29 am
Posts: 27
Location: Rheinland
Maybe this is a bug then anyway? Not sure if it should work or not without A, only Chris can tell. ;)

Edit: Ah, there is a line in help file, you have found it already I think...:
Quote:
The Last Found Window is not updated or accessed by #IfWin.

Well, I didn't know that too, it's just that I am used to always use A because of some strange results I had when omitting it even with the "normal" IfWinActive.

Icfu


Report this post
Top
 Profile  
Reply with quote  
 Post subject: why doesn't this work?
PostPosted: November 12th, 2006, 8:38 pm 
Offline

Joined: November 12th, 2006, 8:34 pm
Posts: 1
Total noob to AutoHotkey. I've been reading here, and am trying to pass locate32's search result listed files to Total Commander. Why doesn't this work?

Code:
;Ctrl-F (Locate: finds selected file in TC)
;This works only with the english localization of Locate
#IfWinActive Locate, Presets
^f::
   sFileName := ""
   sPath := ""
   ControlGet sActiveRow, LIST, SELECTED, SysListView321, A
   StringSplit aRowElements, sActiveRow, %A_Tab%
   sFileName := aRowElements1
   sPath := aRowElements2
   MsgBox %sActiveRow%

   if (sFileName != "")
   {
      Run "c:\wincmd\Totalcmd.exe" /O /T "%sPath%"
      WinWaitActive ahk_class TTOTAL_CMD

      PostMessage 1075, 2915 ;call quicksearch box
      WinWaitActive ahk_class TQUICKSEARCH
      ControlSetText TTabEdit1, %sFileName%
      ControlSend TTabEdit1, {Down}{Esc}
   }
   Return

_________________
No authoritarians were tortured in the writing of this post.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2006, 2:00 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I'm not familiar enough with locate32 or Total Commander to give much help. Try breaking the goal down into smaller pieces and verify that each one works independently. When they do, that's the time to combine them.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2006, 10:01 am 
Offline

Joined: July 24th, 2005, 4:29 am
Posts: 27
Location: Rheinland
This is an adjusted script which waits for successful path change and should work flawlessly.

Code:
#IfWinActive, Locate ahk_class #32770
^f::
sFileName := ""
sPath := ""
ControlGet, sActiveRow, List, Selected, SysListView321
StringSplit, aRowElements, sActiveRow, %A_Tab%
sFileName := aRowElements1
sPath := aRowElements2

If (sFileName)
{
  Run, "%COMMANDER_PATH%\TOTALCMD.EXE" /O /T /S /L="%sPath%"
  WinWaitActive, ahk_class TTOTAL_CMD
  Loop
  {
  ControlGetText, ActivePath, TMyPanel2
  StringTrimRight, ActivePath, ActivePath, 1
  If (ActivePath = sPath)
    Break
  }
  PostMessage, 1075, 2915
  WinWaitActive, ahk_class TQUICKSEARCH
  ControlSetText, TTabEdit1, %sFileName%
  ControlSend, TTabEdit1, {Down}{Esc}
}
Return


Icfu


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2006, 11:12 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
You should change
Code:
Run, "%COMMANDER_PATH%\TOTALCMD.EXE" /O /T /S /L="%sPath%"

part.

Its louzy cuz TC is probably already started so this "redirection" will be slow.
Instead, set the path with this function imediatelly:

Code:
DialogSetPath_TC(path, bTab = false)
{
   global

   if (bTab)
      SendTCCommand(cm_OpenNewTab)
   
   WinActivate ahk_class TTOTAL_CMD

   SendTCCommand(cm_editpath)
   SendRaw, %path%
   Send, {ENTER}
}


This is the whole new script

Code:
SetKeyDelay, -1
SetBatchLines -1

#IfWinActive, Locate ahk_class #32770

^f::
   sFileName := ""
   sPath := ""
   ControlGet, sActiveRow, List, Selected, SysListView321
   StringSplit, aRowElements, sActiveRow, %A_Tab%
   sFileName := aRowElements1
   sPath := aRowElements2

   If (sFileName)
   {
     SetTCPath( sPath )
     WinWaitActive, ahk_class TTOTAL_CMD

     Loop
     {
        ControlGetText, ActivePath, TMyPanel2
        StringTrimRight, ActivePath, ActivePath, 1
        If (ActivePath = sPath)
         Break
     }
    
     PostMessage, 1075, 2915
     WinWaitActive, ahk_class TQUICKSEARCH
     ControlSetText, TTabEdit1, %sFileName%
     ControlSend, TTabEdit1, {Down}{Esc}
   }
return


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

SetTCPath(path)
{
   if !WinExist("ahk_class TTOTAL_CMD")
   {
      Run, %COMMANDER_PATH%\TOTALCMD.EXE
      WinWait ahk_class TTOTAL_CMD
   }

   WinActivate ahk_class TTOTAL_CMD

   SendTCCommand(2912)
   SendRaw, %path%
   Send, {ENTER}
}

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

SendTCCommand(cmd, wait=1)
{
   if (wait)
      SendMessage 1075, cmd, 0, , ahk_class TTOTAL_CMD
   else
      PostMessage 1075, cmd, 0, , ahk_class TTOTAL_CMD
}



Now, this works instantious here :mrgreen:


The best way to use this script is to use Locate from TC with option -P %P% .

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 13th, 2006, 12:12 pm 
majkinetor wrote:
The best way to use this script is to use Locate from TC with option -P %P% .


Thanks, the script works very fast from within Locate, with just a ctrl-f. I'd need more explanation of this from TC with option -P %P% to understand what you mean.

One thing this script isn't doing for me...

Naturally, if TC is to display a file, it's going to be in context, in its containing folder, with any other files there. Fine. But what I wanted even more was to be able in Locate to ctrl-a all search results, for example all jpgs on a partition, and then have a ctrl-f send the whole list to TC's search results list, ready to use TC's Feed to Listbox. Any way to script that?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2006, 12:32 pm 
Offline

Joined: July 24th, 2005, 4:29 am
Posts: 27
Location: Rheinland
Quote:
Any way to script that?

Nope, there's no way to script that as TC doesn't support feeding a list with items from the outside.

@majki:
You are right when TC is started already of course, but I don't expect others to have TC always started, at least not in this forum here... ;)

Also keep in mind that cm_EditPath doesn't work when path display is off! That's why for the public it's better to stick with command line parameters, cd in command line or this WM_COPYDATA solution which always works:

Code:
SetKeyDelay, -1
SetBatchLines -1

#IfWinActive, Locate ahk_class #32770

^f::
   sFileName := ""
   sPath := ""
   ControlGet, sActiveRow, List, Selected, SysListView321
   StringSplit, aRowElements, sActiveRow, %A_Tab%
   sFileName := aRowElements1
   sPath := aRowElements2

   If (sFileName)
   {
     SetTCPath( sPath )
     WinWaitActive, ahk_class TTOTAL_CMD

     Loop
     {
        ControlGetText, ActivePath, TMyPanel2
        StringTrimRight, ActivePath, ActivePath, 1
        If (ActivePath = sPath)
         Break
     }

     PostMessage, 1075, 2915
     WinWaitActive, ahk_class TQUICKSEARCH
     ControlSetText, TTabEdit1, %sFileName%
     ControlSend, TTabEdit1, {Down}{Esc}
   }
return


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

SetTCPath(path)
{
   if !WinExist("ahk_class TTOTAL_CMD")
   {
      Run, %COMMANDER_PATH%\TOTALCMD.EXE
      WinWait ahk_class TTOTAL_CMD
   }

   WinActivate ahk_class TTOTAL_CMD

   path := path "`r"
   VarSetCapacity( CopyDataStruct, 12 )
   InsertInteger( Asc( "C" ) + 256 * Asc( "D" ), CopyDataStruct )
   InsertInteger( StrLen( path ) + 5, CopyDataStruct, 4 )
   InsertInteger( &path, CopyDataStruct, 8 )
   InsertInteger( Asc( "S" ), path, StrLen( path ) + 1, 1)
   InsertInteger( Asc( "T" ), path, StrLen( path ) + 2, 1)
   SendMessage, 0x4A, , &CopyDataStruct, , ahk_class TTOTAL_CMD

}

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

SendTCCommand(cmd, wait=1)
{
   if (wait)
      SendMessage 1075, cmd, 0, , ahk_class TTOTAL_CMD
   else
      PostMessage 1075, cmd, 0, , ahk_class TTOTAL_CMD
}

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

InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
{
  mask := 0xFF
  Loop %pSize%
  {
    DllCall("RtlFillMemory", UInt, &pDest + pOffset + A_Index - 1, UInt, 1, UChar, (pInteger & mask) >> 8 * (A_Index - 1))
    mask := mask << 8
  }
}


Icfu


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2006, 12:53 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
2icfu
Even better solution. Doesn't flicker :) Now, if we only can find a way to select a file name without quick search.... :)

Quote:
cd in command line

this can also be disabled...


2taterhead-again
Icfu is right, no way. About -P %P% it goes this way:

Code:
1. Start->Change Start Menu
2. Add Item
3. Set new item like this:
    Command : D:\Utils\Locate\Locate32.exe
    Parameters: -P "%P"

From that moment you can use Locate from the start menu with the current TC folder.

_________________
Image


Last edited by majkinetor on November 13th, 2006, 2:01 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Maestr0, XstatyK and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group