Interacting with textbox in other application

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Kametec
Posts: 1
Joined: 04 Aug 2021, 19:35

Interacting with textbox in other application

04 Aug 2021, 20:44

Hi,
I've just stumbled upon AHK when looking for a way to save me some mouse pointing and clicking. Having an electronic dictionary is great time saver by itself, but I'd like to take it a step further. I'm looking for following functionality:

I select some text, then hit a hotkey which launches a script which copies selected text, pastes it into dictionary and searches it.

I have found AHK and looked into its extensive scripting options and it seems like it is the tool I'm looking for, but since I just started familiarizing myself with it, I'm a bit lost and I'd like to ask for help.

I've figured the macro should do the following:
  1. Copy the selected text into clipboard. I assume "pressing" ctrl+c would do the trick and I have figured out how to do it. But I am curious, is there a way to save it to clipboard directly and is better to do it that way?
  2. Activate the dictionary window. I have figured out this one as well.
  3. Focus the search textbox. I have no idea how to do that. Examples I've seen work with Notepad, which has focus on the typing area when it gets activated, which is not the case in here. I'm under impression that interacting with contents of other windows is possible somehow, but I haven't figured it out yet. The scripting help is huge and I haven't familiarized with various options I have yet. Which methods should I look up? I have a picture of the dictionary window and the search textbox is marked by "1" on it.
  4. Paste the text from clipboard over any text which may be present. "Pressing" ctrl+a and ctrl+v should work.
  5. Running the search. Either hitting enter or clicking search button works. I am considering "pressing" enter because it seems much easier than pressing the button, but the reason behind that is that I have no idea how to approach the button route. For completness' sake I have marked the button as "2" on the picture.
Image

Any help would be much appreciated. I'm looking for either pointers so I can write the script myself or a script I could dissect and learn from it.

Thanks in advance!
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Interacting with textbox in other application

04 Aug 2021, 22:58

Welcome to AutoHotkey. I would suggest reading some of the documentation, especially the introduction and the Send command. You can assign hotkeys to issue whatever Send ("press") commands you want. You could create some short test scripts that do that, to send ^c, ^f, or other keys or sequences. That is a way to get started. You can also search the forum here for solutions to specific issues with specific programs, as needed. You can post your actual test scripts here for feedback about them. Microsoft Word does have its own way to manage keyboard shortcuts, so you have a choice of whether to use that or AHK (for example). A few starting ideas are below.

Code: Select all

#IfWinActive ahk_exe WINWORD.exe
F3::Send ^c   ; F3 = Copy
F7::Send ^f   ; F7 = Find
~LButton Up:: ; Left button = Copy
ControlGetFocus, fc, A
If (fc != "_WwG1")
 Return
Clipboard =
Send ^c
ClipWait, 0
If !ErrorLevel
 MsgBox, 64, Copied, %Clipboard%
Return
#IfWinActive

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dipahk, Nerafius and 193 guests