Return to text field input box after grabbing text from address bar?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Return to text field input box after grabbing text from address bar?

Post by newcod3r » 30 Dec 2021, 20:42

Is there a way for AutoHotkey to tell the current input box I'm using, so that I can return focus to it after I'm done grabbing text from the address bar in Chrome?

Example below, but there may be other sites with multiple boxes (E.g. for newsletter signup, they ask for email, name, phone etc)

Image

User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Return to text field input box after grabbing text from address bar?

Post by mikeyww » 31 Dec 2021, 08:20

There is perhaps no need.

Code: Select all

#Include D:\utils\acc.ahk ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=26201
MsgBox, 64, Chrome URL, % url := Acc_Get("Object", "4.1.1.2.1.2.5.3",, "ahk_exe chrome.exe").accValue(0)

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Return to text field input box after grabbing text from address bar?

Post by amateur+ » 31 Dec 2021, 08:48

Or

Code: Select all

Acc_Get("Object","4.1.1.2.1.2.6.3",0,"A").accValue(0)
; Acc_Get("Object","4.1.1.2.1.2.6.3",0,"ahk_exe brave.exe").accValue(0)
for Brave browser.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: Return to text field input box after grabbing text from address bar?

Post by newcod3r » 31 Dec 2021, 22:37

mikeyww wrote:
31 Dec 2021, 08:20
There is perhaps no need.

Code: Select all

#Include D:\utils\acc.ahk ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=26201
MsgBox, 64, Chrome URL, % url := Acc_Get("Object", "4.1.1.2.1.2.5.3",, "ahk_exe chrome.exe").accValue(0)
hmm this returns the URL. I was just asking how to tell the current text field I'm in (for this example, it's "search quotes...") so I can easily return to it later..

User avatar
boiler
Posts: 16912
Joined: 21 Dec 2014, 02:44

Re: Return to text field input box after grabbing text from address bar?

Post by boiler » 31 Dec 2021, 23:31

His point was that if you can grab the URL with the method he showed, then you don’t have to leave the current input box to grab the URL. You don’t have to return to something that you never left. That was the problem as you described it.

For your other case with multiple input boxes, it seems that you would be able to Tab and Shift+Tab to navigate between them.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: Return to text field input box after grabbing text from address bar?

Post by newcod3r » 01 Jan 2022, 21:06

boiler wrote:
31 Dec 2021, 23:31
His point was that if you can grab the URL with the method he showed, then you don’t have to leave the current input box to grab the URL. You don’t have to return to something that you never left. That was the problem as you described it.

For your other case with multiple input boxes, it seems that you would be able to Tab and Shift+Tab to navigate between them.
ah! ok I get it now. Thanks for explaining.

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: Return to text field input box after grabbing text from address bar?

Post by mrmech » 19 Nov 2022, 18:45

I also want to get the web address from the URL search bar so I'm interested in using ACC but I don't know how to get started. I downloaded this: https://github.com/Descolada/UIAutomation but where do I save the files? Can I use the same scripts from above or will I have to do something different since it's UIAutomation? Thanks

User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Return to text field input box after grabbing text from address bar?

Post by mikeyww » 19 Nov 2022, 19:03

Something different. This worked for me, though I'm not sure if there's a better way. You can put the files where you wish, or see documentation as noted. viewtopic.php?p=492106#p492106

Code: Select all

#Include d:\utils\UIAutomation-main\Lib\UIA_Interface.ahk
#Include d:\utils\UIAutomation-main\Lib\UIA_Browser.ahk
winTitle  = ahk_exe chrome.exe
WinActivate, %winTitle%
cUIA     := new UIA_Browser(winTitle)
url      := cUIA.GetCurrentURL()
MsgBox, 64, URL, %url%

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: Return to text field input box after grabbing text from address bar?

Post by mrmech » 20 Nov 2022, 09:39

Thanks, Mikeyww. I'll give this a shot!

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: Return to text field input box after grabbing text from address bar?

Post by mrmech » 20 Nov 2022, 11:17

I tried it, but I think there's a problem with the cUIA := new UIA_Browser(winTitle) line because that's where your script stops working. When I open UIA_Browser.ahk, I get an error message:

Code: Select all

Error:  Call to nonexistent function.

Specifically: UIA_Interface(maxVersion)

	Line#
	297: Send,{LCtrl up}{LAlt up}{LShift up}{RCtrl up}{RAlt up}{RShift up}
	298: Send,{Ctrl down}w{Ctrl up}
	299: }
	303: {
	304: this.BrowserId := WinExist(wTitle)  
	305: if !this.BrowserId  
	306: Throw,Exception("UIA_Browser: failed to find the browser!", -1)
--->	307: this.UIA := UIA_Interface(maxVersion)  
	308: this.TWT := this.UIA.TreeWalkerTrue  
	309: this.CustomNames := (customNames == "") ? {} : customNames  
	310: this.TextControlCondition := this.CreatePropertyCondition(this.UIA.ControlTypePropertyId, this.UIA.TextControlTypeId)  
	311: this.ButtonControlCondition := this.CreatePropertyCondition(this.UIA.ControlTypePropertyId, this.UIA.ButtonControlTypeId)  
	312: this.EditControlCondition := this.UIA.CreatePropertyCondition(this.UIA.ControlTypePropertyId, this.UIA.EditControlTypeId)  
	313: this.ToolbarControlCondition := this.UIA.CreatePropertyCondition(this.UIA.ControlTypePropertyId, this.UIA.ToolBarControlTypeId)  
	314: this.TabControlCondition := this.UIA.CreatePropertyCondition(this.UIA.ControlTypePropertyId, this.UIA.TabControlTypeId)  

The program will exit.

Descolada
Posts: 1123
Joined: 23 Dec 2021, 02:30

Re: Return to text field input box after grabbing text from address bar?

Post by Descolada » 20 Nov 2022, 11:27

@mrmech you need to #include both UIA_Interface.ahk and UIA_Browser.ahk into your script, just like mikeyww did with

Code: Select all

#Include d:\utils\UIAutomation-main\Lib\UIA_Interface.ahk
#Include d:\utils\UIAutomation-main\Lib\UIA_Browser.ahk
An easier option would be to use the GetUrl function instead, if you only need the current address.

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: Return to text field input box after grabbing text from address bar?

Post by mrmech » 20 Nov 2022, 12:52

Thanks for the note, Descolada. Here's the script I have, I think it has your suggestion but it doesn't work:

Code: Select all

#Include C:\Program Files\AutoHotkey UIAutomation\UIAutomation-main\Lib\UIA_Interface.ahk
#Include C:\Program Files\AutoHotkey UIAutomation\UIAutomation-main\Lib\UIA_Browser.ahk
winTitle  = ahk_exe chrome.exe
WinActivate, %winTitle%
cUIA     := new UIA_Browser(winTitle)
url      := cUIA.GetCurrentURL()
MsgBox, 64, URL, %url%

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: Return to text field input box after grabbing text from address bar?

Post by mrmech » 20 Nov 2022, 16:43

The GetUrl function is easy so I'm probably going to go with that. But, I am curious about what's wrong with the other one I tried. Also, is there any benefit to using the GetURL function with UIAutomation?

Thanks for the help!

Descolada
Posts: 1123
Joined: 23 Dec 2021, 02:30

Re: Return to text field input box after grabbing text from address bar?

Post by Descolada » 21 Nov 2022, 00:07

@mrmech, the "bare" GetUrl I linked in my post is just using "raw" UIAutomation calls with DllCalls, which UIA_Interface.ahk uses as well but is wrapped up in more convenient to use functions. This means that using the "bare" GetUrl will probably have a speed increase compared to using UIA_Interface.ahk and UIA_Browser.ahk. The advantages of using UIA_Interface.ahk is that if you need to do additional things with the browser (eg click links, wait page loads, detect click events etc), then with UIA_Interface.ahk it's much much easier to achieve that.

As to what went wrong with your code, the error means that the main UIA_Interface() function wasn't found, which means that UIA_Interface.ahk was probably not properly loaded. I would try downloading it again to make sure you don't have a broken copy of it. Better yet, download the whole package from GitHub (green Code button -> Download ZIP) and try to get the example files running first.

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: Return to text field input box after grabbing text from address bar?

Post by mrmech » 29 Nov 2022, 09:25

Thanks for the explanation. I'll give the download another shot.

Post Reply

Return to “Ask for Help (v1)”