 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
SanskritFritz
Joined: 17 Feb 2005 Posts: 283 Location: Hungary, Budapest
|
Posted: Thu Feb 02, 2006 4:27 pm Post subject: Problem: #IfWinActive with Locate |
|
|
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? |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Fri Feb 03, 2006 3:38 am Post subject: Re: Problem: #IfWinActive with Locate |
|
|
| 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. |
|
| Back to top |
|
 |
SanskritFritz
Joined: 17 Feb 2005 Posts: 283 Location: Hungary, Budapest
|
Posted: Fri Feb 03, 2006 9:41 am Post subject: Re: Problem: #IfWinActive with Locate |
|
|
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? |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Fri Feb 03, 2006 11:33 am Post subject: Re: Problem: #IfWinActive with Locate |
|
|
| 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. |
|
| Back to top |
|
 |
SanskritFritz
Joined: 17 Feb 2005 Posts: 283 Location: Hungary, Budapest
|
Posted: Fri Feb 03, 2006 11:56 am Post subject: |
|
|
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? |
|
| Back to top |
|
 |
Icfu
Joined: 24 Jul 2005 Posts: 27 Location: Rheinland
|
Posted: Fri Feb 03, 2006 4:16 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
SanskritFritz
Joined: 17 Feb 2005 Posts: 283 Location: Hungary, Budapest
|
Posted: Fri Feb 03, 2006 5:07 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
Icfu
Joined: 24 Jul 2005 Posts: 27 Location: Rheinland
|
Posted: Fri Feb 03, 2006 5:30 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
taterhead
Joined: 12 Nov 2006 Posts: 1
|
Posted: Sun Nov 12, 2006 8:38 pm Post subject: why doesn't this work? |
|
|
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. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Mon Nov 13, 2006 2:00 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Icfu
Joined: 24 Jul 2005 Posts: 27 Location: Rheinland
|
Posted: Mon Nov 13, 2006 10:01 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Mon Nov 13, 2006 11:12 am Post subject: |
|
|
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
The best way to use this script is to use Locate from TC with option -P %P% . _________________
 |
|
| Back to top |
|
 |
taterhead-again Guest
|
Posted: Mon Nov 13, 2006 12:12 pm Post subject: works great for single file, but... |
|
|
| 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? |
|
| Back to top |
|
 |
Icfu
Joined: 24 Jul 2005 Posts: 27 Location: Rheinland
|
Posted: Mon Nov 13, 2006 12:32 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Mon Nov 13, 2006 12:53 pm Post subject: |
|
|
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. _________________

Last edited by majkinetor on Mon Nov 13, 2006 2:01 pm; edited 1 time in total |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|