Automatically focus cursor on copied file/folder

English support forum

Moderators: white, Hacker, petermad, Stefan2

wetware05
Junior Member
Junior Member
Posts: 64
Joined: 2023-05-15, 16:10 UTC

Re: Automatically focus cursor on copied file/folder

Post by *wetware05 »

Hacker wrote: 2023-06-20, 20:29 UTC wetware05,
That the file name is copied into a variable directly, without going through the clipboard, or is it not possible?
Not in a way I would know of. The file under the cursor yes, but not the selected files. Perhaps the selection could be saved to a file, the file then read by the script and deleted, but that seems cumbersome. Perhaps someone has a better idea?

Roman
I just want the file under the cursor. I have a procedure through the UIA function, but I think it gives me errors sometimes, and I want to "get rid" of that function.
User avatar
Hacker
Moderator
Moderator
Posts: 13067
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Automatically focus cursor on copied file/folder

Post by *Hacker »

wetware05,
I currently don't have time to test this, but the standard listbox functions should work, if you're willing to try them:

Code: Select all

LB_FindCursorPos( byRef cID )
{
	LB_GETCURSEL = 0x188
	NULL = 0x0
	SendMessage, LB_GETCURSEL, NULL, NULL,, ahk_id %cID%
;MsgBox, EL: %ErrorLevel%
return ( ErrorLevel <> "FAIL" ? ErrorLevel + 1 : 0 )
}

LB_QueryText( cID, cPos )
{
	LB_GETTEXT = 0x189
	VarSetCapacity(text,512)
	SendMessage, LB_GETTEXT, % cPos - 1, &text,, ahk_id %cID%
return text
}
HTH
Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
wetware05
Junior Member
Junior Member
Posts: 64
Joined: 2023-05-15, 16:10 UTC

Re: Automatically focus cursor on copied file/folder

Post by *wetware05 »

Hacker wrote: 2023-06-20, 21:33 UTC wetware05,
I currently don't have time to test this, but the standard listbox functions should work, if you're willing to try them:

Code: Select all

LB_FindCursorPos( byRef cID )
{
	LB_GETCURSEL = 0x188
	NULL = 0x0
	SendMessage, LB_GETCURSEL, NULL, NULL,, ahk_id %cID%
;MsgBox, EL: %ErrorLevel%
return ( ErrorLevel <> "FAIL" ? ErrorLevel + 1 : 0 )
}

LB_QueryText( cID, cPos )
{
	LB_GETTEXT = 0x189
	VarSetCapacity(text,512)
	SendMessage, LB_GETTEXT, % cPos - 1, &text,, ahk_id %cID%
return text
}
HTH
Roman
I can't deduce in which variable the name of the file is saved... :roll: txt?
User avatar
Hacker
Moderator
Moderator
Posts: 13067
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Automatically focus cursor on copied file/folder

Post by *Hacker »

wetware05,
Yes, variable text should be the one with the name. But as I said, I did not test it.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
linuxy
Junior Member
Junior Member
Posts: 33
Joined: 2022-03-03, 22:07 UTC

Re: Automatically focus cursor on copied file/folder

Post by *linuxy »

petermad wrote: 2023-06-19, 09:04 UTC 2linuxy & 2Seyran_72

What should happen if you copy more than one file - should TC go to the file that corresponds to the file under the cursor in the source side (which might not even had been selected for copying) or to the last selected file, or to the last copied file, or to the first selected/copied files?

Or should it only work when one item is copied?
Just like Windows Explorer, Xyplorer, Dopus, etc:

I'm just talking about when 1 file or 1 folder is copied/moved, to simply focus/highlight/select it after the operation is done. So we don't have to scroll and find a needle in a haystack, or script a button, or scroll to the end of the directory, etc.

Just 1 item, or 1 folder copied/moved, yes. Thank you. It's greatly effective, power users.

I know TC is old school, and the user base are firmly set in their ways but I hope TC can evolve and not be stuck treading water. I love TC. I want it to continue to be awesome! No need to make things more difficult just because lol :)
wetware05
Junior Member
Junior Member
Posts: 64
Joined: 2023-05-15, 16:10 UTC

Re: Automatically focus cursor on copied file/folder

Post by *wetware05 »

Hacker, your script didn't work.
In the end I understood that for the ACC function to work well, you have to assign a control to it.

This is the script that works for Total Commander, in case someone wants to use it. The path is obtained with a part of the "hacker" routine, and ACC takes the name under the mouse, if the Total Commander panel is in full view, with file size extension and creation date, since the RegExMatch command is stays with the name (text before the first tab). I don't know if it works in other view modes, RegExMatch would have to be adapted.

Code: Select all

#NoEnv

SetTimer, Timer
Return

Timer:
ToolTip % GetNameOfIconUnderMouse()

Return

Esc::ExitApp

GetNameOfIconUnderMouse() {
   MouseGetPos, , , hwnd, CtrlClass
   WinGetClass, WinClass, ahk_id %hwnd%
   If (WinClass = "TTOTAL_CMD" && CtrlClass = "LCLListBox1" or CtrlClass = "LCLListBox2" or CtrlClass = "TMyListBox1" or CtrlClass = "TMyListBox2")
    {
     SendMessage, 1074, 1000, , , ahk_class TTOTAL_CMD
     SendMessage, 1074, 8 + ErrorLevel, , , ahk_class TTOTAL_CMD
     ControlGetText, TargetPath, , ahk_id %ErrorLevel%
     sPath := SubStr(TargetPath, 1, InStr(TargetPath, "\", , 0) - 1)
      oAcc := Acc_ObjectFromPoint(ChildID)
      Name := ChildID ? oAcc.accName(ChildID) : ""
      RegExMatch(Name, "^[^\t]*", Reg)
      Name := sPath "\" Reg    
     Return Name
    }
}

; https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk
Acc_Init() {
	Static h
	If Not h
		h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "") {
	Acc_Init()
	If	DllCall("oleacc\AccessibleObjectFromPoint", "Int64", x==""||y==""?0*DllCall("GetCursorPos","Int64*",pt)+pt:x&0xFFFFFFFF|y<<32, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
	Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Acc_Parent(Acc) { 
	try parent:=Acc.accParent
	return parent?Acc_Query(parent):
}
Acc_Query(Acc) { ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
	try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}
The name of the file appears in a "ToolTip", the variable that contains the name and the path is "name", or the name of the function: GetNameOfIconUnderMouse()

Regarding the linuxy request, there is an option for total commander to set a color type to recent files. Another issue is that the panel is set to show new files on top (Sort by recent dates Ctrl-F5). You could write a script in autohotkey that "digests" what new files or folders are in one of the panels. But my guess is that what linuxy wants is for TCM to do it natively.

From my point of view, the way things work is fine. You have control of the focus, you know where it is, if it automatically changed, as requested by linuxy, it would annoy most people who are used to having control of the focus. It would be a source of errors and mistakes. (My way of working is that the right pane is what I work on —source— and the left pane is the "destination" or child directory; if I switch focus to the left pane, I swap the panes —Ctrl-U— to restore my " mental order" of how I work with TCM). I seldom use explorer or other source files.... working with explorer is very slow and clunky... if I need more windows open, I open another instance of Total Commander.
User avatar
Hacker
Moderator
Moderator
Posts: 13067
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Automatically focus cursor on copied file/folder

Post by *Hacker »

wetware05,
your script didn't work.
Well, I didn't post any working script ¯\_(ツ)_/¯
You have control of the focus, you know where it is, if it automatically changed, as requested by linuxy, it would annoy most people who are used to having control of the focus.
Well, perhaps it would be enough (for linuxy) to set the cursor in the inactive panel to the copied item, but not activate the panel itself. Or it could be made configurable.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
Post Reply