Apply action only to a certain type of ClassNN control Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Apply action only to a certain type of ClassNN control

Post by Lem2001 » 17 Jan 2022, 18:50

I want to run some code (within a specific application) whenever a ComboBox control has focus, and some different code if a multi-line text edit box has focus. For any other type of control other than these two, nothing should be done.

I've looked at GUIControlGet but it only seems to retrieve things like the actual content of the ComboBox (or its class name or position or whatever) but I can't figure out how to do determine the type of control that it is, so that I can single out ComboBoxes and Multi-line text edit boxes (not single-line edit boxes).

I want to do something like this:

if currently active control is of type: ComboBox, then do <this>
if currently active control is of type: Multi-line text edit, then do <that>
... else do nothing.


Any help appreciated.

User avatar
lmstearn
Posts: 688
Joined: 11 Aug 2016, 02:32
Contact:

Re: Apply action only to a certain type of ClassNN control

Post by lmstearn » 18 Jan 2022, 03:51

Hi, an easy way to id the controls is with the AU3_Spy utility bundled with AHK install. There's also a much smaller WindowSpy.ahk in there which isn't quite so reliable- check out the code for sure.
Multiline edit boxes have the ES_MULTILINE style, once you have the handle of the control, use WinGet to retrieve the style. :)
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: Apply action only to a certain type of ClassNN control

Post by gregster » 18 Jan 2022, 04:26

lmstearn wrote:
18 Jan 2022, 03:51
an easy way to id the controls is with the AU3_Spy utility bundled with AHK install. There's also a much smaller WindowSpy.ahk in there which isn't quite so reliable
AU3_Spy hasn't been included anymore in recent AHK versions, afaik.
But it's news to me that WindowSpy - which replaced it - should be less reliable.

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

Re: Apply action only to a certain type of ClassNN control

Post by amateur+ » 18 Jan 2022, 04:40

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.

User avatar
lmstearn
Posts: 688
Joined: 11 Aug 2016, 02:32
Contact:

Re: Apply action only to a certain type of ClassNN control

Post by lmstearn » 18 Jan 2022, 08:19

gregster wrote:
18 Jan 2022, 04:26
lmstearn wrote:
18 Jan 2022, 03:51
an easy way to id the controls is with the AU3_Spy utility bundled with AHK install. There's also a much smaller WindowSpy.ahk in there which isn't quite so reliable
AU3_Spy hasn't been included anymore in recent AHK versions, afaik.
But it's news to me that WindowSpy - which replaced it - should be less reliable.
AU3_Spy only gets removed if AHK is uninstalled, so long time users like me never knew. ;) Reliable is a bad word, the script won't pick up the controls in some apps, e.g. Chrome, MS Teams, Windows Snipping Tool. Amateur's linked script looks like it will do the job. :)
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: Apply action only to a certain type of ClassNN control

Post by Lem2001 » 19 Jan 2022, 21:45

lmstearn wrote:
18 Jan 2022, 03:51
once you have the handle of the control, use WinGet ...
Thanks very much for your reply.

I know how to use WinSpy, but I don't understand what you mean by the "handle" of "the control".

Spy only shows the class name and there are masses of these combo boxes in this app (and their classNN names constantly change) so trying to target each one individually is not feasible or desirable. That's why I want to select only based on type of control (or, as it seems to be referred to by WinGet, "style" of control).

User avatar
lmstearn
Posts: 688
Joined: 11 Aug 2016, 02:32
Contact:

Re: Apply action only to a certain type of ClassNN control  Topic is solved

Post by lmstearn » 19 Jan 2022, 22:07

Here's info on the handle or HWND, along with a thread.
Dr. Google also helped out by retrieving @LinearSpoon's contribution to this thread. :)
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Apply action only to a certain type of ClassNN control

Post by SOTE » 20 Jan 2022, 05:44

@Lem2001

ahk_id/handle/HWND

"Each window or control has a unique ID, also known as a HWND (short for handle to window). This ID can be used to identify the window or control..."

You can even quickly code your own simple version of AU3/AHK/WindowSpy to display info that you want, like below.

Code: Select all

#Persistent
SetTimer, CursorWatch, 200
return

^p::pause

^g::
ControlGetText, WinInfo,,ahk_class tooltips_class32
WinInfo := StrReplace(WinInfo, A_Space . A_Space, "`r`n")
WinInfo := LTrim(WinInfo)
ClipBoard := WinInfo
Return

CursorWatch:
MouseGetPos, OutputVarX, OutputVarY, id, control
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
WinGet, ActivePath, ProcessPath, A
ControlGetText, ControlText, %control%, A
ControlGet, ControlHwnd, Hwnd,, %control%, A
PixelGetColor, color, %OutputVarX%, %OutputVarY%
If not WinActive("Notepad") AND (control != "Edit1")
{
	ToolTip, ahk_id: %id%  `nahk_class: %class%  `nWindow Title: %title%  `nActive Path: %ActivePath%  `nControl: %control%  `nControlText: %ControlText%  `nMousePos: %OutputVarX%x%OutputVarY%  `nColor: %color%  `nCursor Info: %A_Cursor%
}
return

esc::ExitApp

Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: Apply action only to a certain type of ClassNN control

Post by Lem2001 » 08 Mar 2022, 06:50

lmstearn wrote:
19 Jan 2022, 22:07
Here's info on the handle or HWND, along with a thread.
Dr. Google also helped out by retrieving @LinearSpoon's contribution to this thread. :)
Thank you @lmstearn. I've now managed to get it working exactly as I wanted.

NopryGoul
Posts: 1
Joined: 01 Aug 2022, 06:35

Re: Apply action only to a certain type of ClassNN control

Post by NopryGoul » 09 Aug 2022, 03:45

Thanks a lot for your help. I had the same problem and had no idea what to do. Actually, I've tried everything except your suggestion, and I'm glad it's worked. Thanks a lot. Btw, I work at [link removed by moderator], so you've helped me improve the site, so I'm really grateful to you. Actually, I'd like to say that I love this community so much. Tbh, I've never seen so many people being ready to help each other totally selflessly. That's what society needs. That's what the world needs, I'd say. So I really appreciate your help. Keep us updated. Best wishes


[Moderator note: This post was apparently edited days after it was posted to add a link to a site, which has been removed. You really should be banned for this. Last warning.]

Post Reply

Return to “Ask for Help (v1)”