ControlGetText behavior when getting path from explorer window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
shako
Posts: 11
Joined: 06 Jun 2019, 15:50

ControlGetText behavior when getting path from explorer window

20 May 2020, 11:33

Hi everyone,
I was using the script below to try and get the path from an explorer window. Turns out it only works if I've already clicked inside the path bar before triggering the script.

Code: Select all

#IfWinActive, ahk_class CabinetWClass
!+q::
ControlGetText, f_text, Edit1 ; get the path
if(ErrorLevel)
MsgBox, Error
else
MsgBox, %f_text%
#IfWinActive
From my understanding of ControlGetText, I thought it made sense since without the bar being focused, Edit1 (ClassNN of the path bar) isn't found. What's confusing to me is why it still works after I remove focus from the bar by clicking somewhere in the explorer window's background.
Appreciate any insights!

[Mod edit: Added provisional topic name.]
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: ControlGetText behavior when getting path from explorer window

20 May 2020, 11:53

There are several functions on the forum to get the path of the current folder in explorer. This is one:

Code: Select all

#\::                                              ;win \
msgbox % Explorer_GetPath() 
return

Explorer_GetPath() {
   WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
   if !(winClass ~= "(Cabinet|Explore)WClass")
      Return
   for window in ComObjCreate("Shell.Application").Windows
      if (hWnd = window.hWnd)
         return window.Document.Folder.Self.Path
}
14.3 & 1.3.7
shako
Posts: 11
Joined: 06 Jun 2019, 15:50

Re: ControlGetText behavior when getting path from explorer window

21 May 2020, 12:40

flyingDman wrote:
20 May 2020, 11:53
There are several functions on the forum to get the path of the current folder in explorer. This is one:

Code: Select all

#\::                                              ;win \
msgbox % Explorer_GetPath() 
return

Explorer_GetPath() {
   WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
   if !(winClass ~= "(Cabinet|Explore)WClass")
      Return
   for window in ComObjCreate("Shell.Application").Windows
      if (hWnd = window.hWnd)
         return window.Document.Folder.Self.Path
}
Thanks! I'm already using something similar which I found here. I actually wanted to know why ControlGetText is behaving the way it is in the scenario I described.
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: ControlGetText behavior when getting path from explorer window

19 Oct 2021, 13:30

shako wrote:
21 May 2020, 12:40
I actually wanted to know why ControlGetText is behaving the way it is in the scenario I described.
I'd like to know the answer to this too (having encountered the exact same problem myself).

Does anybody have any insight on why ControlGetText does not work with the path / breadcrumb bar in Explorer or file dialogs?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, doodles333, Nerafius, ShatterCoder and 76 guests