Control not responding to text Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Control not responding to text

Post by JustinNL » 16 Mar 2021, 09:44

Dear all,

I am using AHK to navigate through an electronic patient file (EPF) as an MD.

I want the cursor to focus to a certain textbox in the EPF using a hotkey function.

For instance I want the cursor to move to the "Conclusion" textbox.
When I use the WindowSpy, it tells me that this textbox is "ThunderRT6TextBox117" as ClassNN and in Text it tells me that it is "Conclusion"
Then if I use

Code: Select all

ControlFocus,Conclusion,A
this does not work, but when I use

Code: Select all

ControlFocus,ThunderRT6TextBox117,A
it does work.

Unfortunately, on another moment, this same textbox may be "ThunderRT6TextBox74" as ClassNN, even though it's completely the same textbox on screen.

Does anyone have a suggestion why this control does not respond to the text and some controls do? And is there a better way to reach such controls?
Imagesearch will probably work, but will have the disadvantage of worse performance.

Thanks in advance!
Best, Justin
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Control not responding to text

Post by BoBo » 16 Mar 2021, 09:48

[...]. When using text, the matching behavior is determined by :arrow: SetTitleMatchMode. If this parameter is blank or omitted, the target window's topmost control will be used.

To operate upon a control's HWND (window handle), leave the Control parameter blank and specify ahk_id %ControlHwnd% for the WinTitle parameter (this also works on hidden controls even when DetectHiddenWindows is Off). The HWND of a control is typically retrieved via ControlGet Hwnd, MouseGetPos, or DllCall().
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Control not responding to text

Post by boiler » 16 Mar 2021, 10:00

Another approach you could try if it lets you advance the focus through the controls by using the Tab key: Send {Tab} in a loop and use ControlGetFocus to get the name of the control that has focus, then check it against one of the known names it could have (if just the two you mentioned) or starts with the correct letters (if no others start the same), then stop looping once it does match sufficiently.
JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Re: Control not responding to text

Post by JustinNL » 16 Mar 2021, 13:40

Thanks for your suggestions.

I take it BoBo suggested to use the Hwnd instead of the controls ClassNN. Unfortunately, the Hwnd also changes each time I load the screen (just like the ThunderRT6TextBox-number)
The suggestion of boiler is nice! I tried looping through the tabs and seeing whether I could match the Control Text to a predefined text.
While this method worked, the control that I'm aiming for can unfortunately not be reached by using tabs.

I looked up AccViewer and I think it can be done using Acc, but I'm not sufficiently skilled in this method.
I'll try with ImageSearch, even though the performance will probably be a bit less.

Thanks again! Justin
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Control not responding to text

Post by boiler » 16 Mar 2021, 13:51

JustinNL wrote:
16 Mar 2021, 13:40
I take it BoBo suggested to use the Hwnd instead of the controls ClassNN. Unfortunately, the Hwnd also changes each time I load the screen (just like the ThunderRT6TextBox-number)
Even though the HWND changes every time, it is meant to be determined dynamically, not by hard-coding in the number. But that would be hard to determine in this case since its name changes and you don’t want to identify it by location.
JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Re: Control not responding to text

Post by JustinNL » 16 Mar 2021, 14:43

You're right, I'd rather not use the location, but right now I think using location is the best way to go.
Even though the performance is not instantaneous like ControlFocus.
Thanks for your help!
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Control not responding to text

Post by Frosti » 16 Mar 2021, 15:04

Try to get the hwnd of main window. Then use that hwnd and get the hwnd of your control. This is my procedure to automate my german EPF software. Sometimes I must use this control hwnd to get the next control hwnd. This is my technique to avoid using ACC.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Control not responding to text

Post by boiler » 16 Mar 2021, 15:10

I suppose you can get all the controls for the window using WinGet, ControlList, and that particular control would probably be the same place in the list even if the name of it changes.
JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Re: Control not responding to text

Post by JustinNL » 18 Mar 2021, 07:40

@boiler Thanks, I'm trying to get WinGet, ControlList into an array to try to see whether it is consistently placed in the same place in the array, is that what you mean, so

Code: Select all

ControlFocus, % Control[70]
for instance if it always shows up in the 70th place?

@Frosti Thanks for the suggestion, could you elaborate on how you do that? So my main window is always the same, I can always access it for instance with

Code: Select all

WinActivate, Neo ZIS|
This always gets me the main window. I can also get the Hwnd then easily. But how will this help to get the Hwnd of my target control?
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Control not responding to text

Post by boiler » 18 Mar 2021, 08:37

JustinNL wrote:
18 Mar 2021, 07:40
@boiler Thanks, I'm trying to get WinGet, ControlList into an array to try to see whether it is consistently placed in the same place in the array, is that what you mean, so

Code: Select all

ControlFocus, % Control[70]
for instance if it always shows up in the 70th place?
Yes, WinGet, OutputVar, ControlList creates a string separated by a linefeed (`n), you can create the array using StrSplit with a `n delimiter.


Edit: Fixed details of using ControlList
Last edited by boiler on 18 Mar 2021, 12:02, edited 1 time in total.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Control not responding to text  Topic is solved

Post by Xtra » 18 Mar 2021, 11:34

Give this a try:

Code: Select all

f::ControlFocusByName("Conclusion")

ControlFocusByName(ControlText, WinTitle := "A", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    winget, controls, ControlList, % WinTitle, % WinText, % ExcludeTitle, % ExcludeText
    Loop, Parse, controls, `n, `r
    {
        ControlGetText, ControlGetTextVar, % A_LoopField, % WinTitle, % WinText, % ExcludeTitle, % ExcludeText
        if (ControlGetTextVar == ControlText)
        {
            ControlFocus, % A_LoopField, % WinTitle, % WinText, % ExcludeTitle, % ExcludeText
            return true
        }
    }
    return false
}
HTH
JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Re: Control not responding to text

Post by JustinNL » 18 Mar 2021, 14:56

Thank you both for the suggestions, I’ll try it out tomorrow!

Just a question, in your script you also fill in the variables that are not obligatory (such as ExcludeTitle). Is this ‘good practice’? Or does this have any benefits in performance of AHK?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Control not responding to text

Post by Xtra » 18 Mar 2021, 15:26

They are optional in case you want to use them. Usually only needed when multiple windows have the same wintitle etc. You can restrict the function to the window you want.
Feel free to edit to your liking.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Control not responding to text

Post by boiler » 18 Mar 2021, 15:28

Also notice that he’s not filling out all the parameters in his function call. Notice in his first line, he only passes one parameter. Inside the function itself, he passes all parameters to other commands because it is the general case where someone may have called the parent function with those parameters, so it is passing them along if they were.
JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Re: Control not responding to text

Post by JustinNL » 22 Mar 2021, 09:25

Thanks, I just found some time to test this and the solution provided by @Xtra worked perfectly!
Post Reply

Return to “Ask for Help (v1)”