Help with ControlSend (or Control)

Get help with using AutoHotkey and its commands and hotkeys
Nixcalo
Posts: 26
Joined: 06 Feb 2018, 04:24

Help with ControlSend (or Control)

12 Jun 2018, 05:12

Hi everyone!

I have been trying for two hours now and I am ready to surrender, as I have to deliver a project and I am running out of time, so I'll just post this query and see if someone helps me.

I am trying to create a script that picks up some text and drops it in a certain box in a Firefox/internet explorer page. It then creates a result and I'd like to copy that result into the clipboard (basically, it's DeepL.com translator, something similar to Google Translate, I want to drop something in the Source box and collect the translation from the Target Box.

Initially, I had a script that did it the straightforward way, that is, copies the text I want into the clipboard, changes to Firefox/Edge (depending on what browser I want to use, I tended to use Firefox), moves the mouse to the relevant point in the screen, clicks there in order to select, pastes the ClipBoard, then moves to the target box, sends Control+A to select all target text, then Control+C to copy that to the clipboard.

The number of problems is huge. To name a few, it's slow, very buggy because of the copy paste typical problems (interaction with other processes), depends on the placement of the windows, and the monitor needs to be ON (I can't create a long loop for a lot of sentences and then turn the monitor OFF).

Then I discovered ControlSend (or Control) so I figured that this could be used to send any text I wanted into the relevant box in the browser and then ControlGetText to get text from the TARGET box.

Here is where I am stuck. I don't exactly know the definition for "CONTROL" so I don' tknow firstly if I am in the right track. What is worse, now, is that I am lost with the syntax of ControlSend.
ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
Supposedly, the key to find the right box in which to drop the text I want lies in the variable "Control". But there is NO way in Window Spy to differentiate btween one box or the other. Actually, in Internet Explorer I just see ClassNN: Internet Explorer_Server1 as "Focused Control" but that doesn't differentiate between the Source box (where I want to place the text) and the Target Box (where I want to pick up the text).
So I have tried (in Internet Explorer)

Code: Select all

Control, EditPaste, Hasta la vista baby, Internet Explorer_Server1, Traductor de Google
THIS ONE ABOVE DOES NOT WORK
and

Code: Select all

ControlSend, Internet Explorer_Server1, ^{a}Hasta la vista baby, Traductor de DeepL
The latter works, but strangely. First, it is relatively slow. Second, it confuses capitalization sometimes (instead of "Hasta la vista baby" it sometimes writes "hAsta la vista baby" or "hasta la vista baby". In a couple of cases, it opened the menu option "Organize favorites" instead!!! And fourth, I CAN'T send control commands. If I try to send the string "^{a}Hasta la vista baby" to select what was written before (to overwrite it), it will do it... a few of the times, but with more probability of opening Organize favourites or confusing capitalization. I have no idea what the shortcut for Organize Favorites is (it was supposed to be Control B but does not work for me!)

When trying to do this in Firefox, Windows Spy WILL NOT give me any information about ClassNN. In Firefox, Windows Spy only tells me about ahk_class and ahk_exe. So when I try this just leaving control blank...

Code: Select all

ControlSend,, ^{a}Hasta la vista baby, Traductor de DeepL
it WORKS! Slowly, but flawlessly! It even does the ^{a} thing perfectly, over and over again!
So this is misterious, the same script works in Firefox but NOT in Internet Explorer?? Anyway, I could live with this, provided I am working with Firefox and NOT with Internet Explorer.
However, in that case when trying to recover the translated result (target box) from Mozilla Firefox, I have a problem. How I am I supposed to get it? I have no ClassNN, no way to identify the box I want and pick up the text from there and copy it into Clipboard. So can't use in principle ControlGetText.
How can I pick text from a particular box In Firefox when there is more than one box???
Unless the solution lies in control's HWND (window handles). But there I got completely lost and perhaps that refers to windows only, not to dialog boxes within a window.

And those were all my attempts. At least I tried!!! :( At this point, I kind of surrendered :(

Unless the solution lies in HWND (window handles), but then I don't know what a window handle is, whether this could apply to a website where are two dialog boxes, and how it is used, as manual is unclear.

Any help? Since I got to insert the text I want into a particular box in Firefox (not in Internet Explorer), how can I recover the text from a different dialog box in that same page? How can I identify that particular box and collect the text in there???

Thank you!
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help with ControlSend (or Control)

12 Jun 2018, 06:03

- In AHK v1.1.27+ you can use:

Code: Select all

q:: ;test ControlSend {Text}
ControlSend, Internet Explorer_Server1, {Text}AaBbCcDdEe, A
return
- You might want to try Internet Explorer and COM.
- See:
WBGet function - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=39869
- And look up:
getElementById [no s]
getElementsByClassName
getElementsByTagName
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Nixcalo
Posts: 26
Joined: 06 Feb 2018, 04:24

Re: Help with ControlSend (or Control)

12 Jun 2018, 07:06

I did check something about COM, but it seemed wildly cryptic for me. Also, does COM only work with IE and not with Firefox?

That WBGet function just seems to get Internet Explorer window Title and Opened URL... can't see how I can use it for my needs.

So, if you understand me, I can use the getElementById [no s], getElementsByClassName and getElementsByTagName functions to get the text from the box I need? And how do I find which ID/ClassName or TagName my required dialog box has?
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help with ControlSend (or Control)

12 Jun 2018, 07:14

- Internet Explorer works with COM but not Firefox AFAIK.
- You could look up: AutoHotkey Firefox Selenium, to explore that option, I haven't tried it myself.
- WBGet gives you a way into an existing Internet Explorer tab, giving you a COM object. Then you can do *everything* with that COM object.
- Look up: AutoHotkey getElementById, etc for examples.
- Use iWB2 Learner to investigate IE tabs (zoom must be set to 100% for the box outlines to align correctly). Download here:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Nixcalo
Posts: 26
Joined: 06 Feb 2018, 04:24

Re: Help with ControlSend (or Control)

12 Jun 2018, 11:00

But do you have any idea HOW i can identify the two dialog boxes that appear within the DeepL.com website so I can do WBGet from the text in one? I have tried AccViewer but it does not give me anything that Win Spy doesn't. Perhaps the data I need can be find in the Inspect element popup option in Internet Explorer?
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help with ControlSend (or Control)

12 Jun 2018, 11:16

WBGet gets access to an Internet Explorer tab. To get the information from specific web elements, e.g. information that iWB2 Learner shows (iWB2 Learner is different from, but looks similar to AccViewer), try searching (googling) for AutoHotkey and any of the 3 'getElement' methods for examples. Every website is different, generally you latch onto the IE tab using WBGet, giving you a COM object, you try to find criteria to identify the element, via a 'getElement' method applied to the COM object, and you get or set the value.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], HPW, tmplinshi and 229 guests