Return to text field input box after grabbing text from address bar?
Return to text field input box after grabbing text from address bar?
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)
Example below, but there may be other sites with multiple boxes (E.g. for newsletter signup, they ask for email, name, phone etc)
Re: Return to text field input box after grabbing text from address bar?
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)
Re: Return to text field input box after grabbing text from address bar?
Or
for Brave browser.
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)
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.
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.
Re: Return to text field input box after grabbing text from address bar?
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..mikeyww wrote: ↑31 Dec 2021, 08:20There 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)
Re: Return to text field input box after grabbing text from address bar?
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.
For your other case with multiple input boxes, it seems that you would be able to Tab and Shift+Tab to navigate between them.
Re: Return to text field input box after grabbing text from address bar?
ah! ok I get it now. Thanks for explaining.boiler wrote: ↑31 Dec 2021, 23:31His 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.
Re: Return to text field input box after grabbing text from address bar?
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
Re: Return to text field input box after grabbing text from address bar?
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%
Re: Return to text field input box after grabbing text from address bar?
Thanks, Mikeyww. I'll give this a shot!
Re: Return to text field input box after grabbing text from address bar?
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.
Re: Return to text field input box after grabbing text from address bar?
@mrmech you need to #include both UIA_Interface.ahk and UIA_Browser.ahk into your script, just like mikeyww did with
An easier option would be to use the GetUrl function instead, if you only need the current address.
Code: Select all
#Include d:\utils\UIAutomation-main\Lib\UIA_Interface.ahk
#Include d:\utils\UIAutomation-main\Lib\UIA_Browser.ahk
Re: Return to text field input box after grabbing text from address bar?
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%
Re: Return to text field input box after grabbing text from address bar?
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!
Thanks for the help!
Re: Return to text field input box after grabbing text from address bar?
@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.
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.
Re: Return to text field input box after grabbing text from address bar?
Thanks for the explanation. I'll give the download another shot.