Place cursor on a file using Autohotkey

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Galizza
Member
Member
Posts: 167
Joined: 2018-09-07, 05:21 UTC

Place cursor on a file using Autohotkey

Post by *Galizza »

Hi, i want to know if it is posible to place Tc cursor on a file which name+extension is stored on a Autohotkey variable. I've tried

Code: Select all

SendInput %Name%
but it doesn't work. Any advice will be welcome, thanks.
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Re: Place cursor on a file using Autohotkey

Post by *Ovg »

Something like:

Code: Select all

Clipboard := YourFileName
PostMessage, 0x433, 2033, 0,,ahk_class TTOTAL_CMD ; Load selection from clipboard
PostMessage, 0x433, 2049, 0,,ahk_class TTOTAL_CMD ; Go to first entry in the list
PostMessage, 0x433, 2053, 0,,ahk_class TTOTAL_CMD ; Go to next selected file
PostMessage, 0x433,  524, 0,,ahk_class TTOTAL_CMD ; Clear selection
Last edited by Ovg on 2023-01-18, 12:52 UTC, edited 1 time in total.
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
Galizza
Member
Member
Posts: 167
Joined: 2018-09-07, 05:21 UTC

Re: Place cursor on a file using Autohotkey

Post by *Galizza »

It works ok, thank you very much :!:
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Re: Place cursor on a file using Autohotkey

Post by *Ovg »

2Galizza
You are welcome! :)
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
Fla$her
Power Member
Power Member
Posts: 2247
Joined: 2020-01-18, 04:03 UTC

Re: Place cursor on a file using Autohotkey

Post by *Fla$her »

2Ovg
2050 or 2054 is also needed, otherwise it will not work if the cursor is lower.
Overquoting is evil! 👎
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Re: Place cursor on a file using Autohotkey

Post by *Ovg »

2Fla$her
You're right! Thank you! :thumbsup:

I've edited my post
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
Fla$her
Power Member
Power Member
Posts: 2247
Joined: 2020-01-18, 04:03 UTC

Re: Place cursor on a file using Autohotkey

Post by *Fla$her »

2Ovg
I assumed that you would choose 2049. :) But then there will be an additional (extra) offset if the desired file is first in the list. Therefore, two other № were offered.
Overquoting is evil! 👎
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Place cursor on a file using Autohotkey

Post by *ghisler(Author) »

Btw, you can lookup these codes in totalcmd.inc, e.g.
cm_LoadSelectionFromClip=2033
Author of Total Commander
https://www.ghisler.com
valuex
Junior Member
Junior Member
Posts: 25
Joined: 2014-12-25, 13:53 UTC

Re: Place cursor on a file using Autohotkey

Post by *valuex »

It doesn't work well when using VBA.
Any idea on how to make it more robust?

The below script is to select the cell in columnA in excel and select the corresponding file in TC to preview file content.

Code: Select all

Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As LongPtr, ByVal wparam As LongPtr, ByVal lParam As LongPtr) As LongPtr
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wparam As Long, lParam As Any) As LongPtr
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If (Target.Count = 1) Then
ThisRowNum = Target.Row
ThisValue = Cells(ThisRowNum, 1).Value
a = StoreData(ThisValue)
' go to file
TC_Hwnd = FindWindow("TTOTAL_CMD", vbNullString)
RST = SendMessage(TC_Hwnd, 1075, 2033, 0)   'cm_LoadSelectionFromClip=2033;Read file selection from clipboard
RST = SendMessage(TC_Hwnd, 1075, 2049, 0)   'cm_GoToFirstEntry=2049;Place cursor on first folder or file
RST = SendMessage(TC_Hwnd, 1075, 2053, 0)   'cm_GoToNextSelected=2053;Go to next selected file
RST = SendMessage(TC_Hwnd, 1075, 524, 0)   'cm_ClearAll=524;Unselect all (files+folders)

End If
End Sub


Function StoreData(varText As Variant) As String
  Dim objCP As Object
  Set objCP = CreateObject("HtmlFile")
  objCP.ParentWindow.ClipboardData.SetData "text", varText
End Function

Excel content in ColumnA looks like:

Code: Select all

C:\Users\xxxxxx\Desktop\00cfe0de-da79-4421-a269-5c3bdea08523.mhtml
C:\Users\xxxxxx\Desktop\00e5698f-9184-436d-a2a6-ef653cc7a1d2.mhtml
C:\Users\xxxxxx\Desktop\00eddb01-105d-4422-8d46-a0f6d8d72b9e.mhtml
C:\Users\xxxxxx\Desktop\00f02f48-8d6d-44cc-a2e9-c3611b16542c.mhtml
C:\Users\xxxxxx\Desktop\00f52e72-e8e2-427b-83b3-f04c32896db3.mhtml
C:\Users\xxxxxx\Desktop\0a0a0bf4-e1e9-4c04-8347-6f0587efa648.mhtml
C:\Users\xxxxxx\Desktop\0a6d9dcf-b99b-4efb-bc7c-27015e4e8dca.mhtml
C:\Users\xxxxxx\Desktop\0a31e3a5-1386-4086-826e-17b162d076a1.mhtml
C:\Users\xxxxxx\Desktop\0a708cea-556d-4089-ab5a-ab1b40a42be9.mhtml
C:\Users\xxxxxx\Desktop\0a7722dd-e8a5-4036-9250-19e0932fe2a9.mhtml
C:\Users\xxxxxx\Desktop\0a37994b-fe75-430e-ad0b-0856e1a0bb28.mhtml
C:\Users\xxxxxx\Desktop\0a268380-4bf9-4912-a986-c51745a82968.mhtml
C:\Users\xxxxxx\Desktop\0ab3db39-af4d-4c5f-bbaa-408f1cafe4a5.mhtml
C:\Users\xxxxxx\Desktop\0ad763ad-9f67-44c9-b511-4cef84b1f124.mhtml
C:\Users\xxxxxx\Desktop\0af70916-1565-41f6-9d63-1a17ff68d4ed.mhtml


valuex
Junior Member
Junior Member
Posts: 25
Joined: 2014-12-25, 13:53 UTC

Re: Place cursor on a file using Autohotkey

Post by *valuex »

Also, if possible, it would be better to have an internal command to like 'cm_LoadSelectionFromClip=2033', instead do file selection, but directly place cursor on the corresponding file.
User avatar
beb
Senior Member
Senior Member
Posts: 430
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Place cursor on a file using Autohotkey

Post by *beb »

valuex wrote: 2024-02-01, 14:14 UTC Also, if possible, it would be better to have an internal command to like 'cm_LoadSelectionFromClip...
Please find an answer, based on the internal commands as requested, in the dedicated topic that you had cleated:
https://ghisler.ch/board/viewtopic.php?t=80927&p=449092#p449092
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
Fla$her
Power Member
Power Member
Posts: 2247
Joined: 2020-01-18, 04:03 UTC

Re: Place cursor on a file using Autohotkey

Post by *Fla$her »

2valuex
Look here and here.
Overquoting is evil! 👎
Post Reply