#IfWinActive to child window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jochen
Posts: 48
Joined: 17 Apr 2016, 11:25

#IfWinActive to child window

03 Dec 2017, 02:32

Hello altogether,
I want to set something like
#IfWinActive, MyProgram, ClassNN: xMyProgramchild01
return::Send, !u

I could not find it in the manual; can anybody help?
Thank you!
Jochen
Posts: 48
Joined: 17 Apr 2016, 11:25

Re: #IfWinActive to child window

08 Dec 2017, 12:25

hmmm. is that question too stupid?
Please don´t let me die ignorant, any hint is welcome!
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: #IfWinActive to child window

08 Dec 2017, 13:44

If, by "return", you mean the Enter key, you should change it to Enter. "Return" is a command used in functions and subroutines.
Jochen
Posts: 48
Joined: 17 Apr 2016, 11:25

Re: #IfWinActive to child window

15 Dec 2017, 23:26

Hi Osprey,
Thanks for you answer, you are totally right of course.
The main problem is that the script does not work, I changed it into:

#IfWinActive, MyProgram, ClassNN: xMyProgram5100doc90121
MsgBox, active

The msg occurs even if the ClassNN xMyProgram5100doc90121 is not mentioned in window spy but xMyProgram5100doc90123
Any help is welcome!
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: #IfWinActive to child window

16 Dec 2017, 02:14

#IfWinActive is a so-called "Directive" and only affects context-sensitive hotkeys and hotstrings (see https://autohotkey.com/docs/commands/_IfWinActive.htm).
A msgbox is neither of that and therefore not affected. That's why it appears every time. A hotkey would be affected.

In this case here, use the command "IfwinActive" instead (https://autohotkey.com/docs/commands/WinActive.htm) - it has no "#". You should also take a look at the syntax. I don't think that "ClassNN xMyProgram5100doc90121" makes sense as "WinText" parameter.
Jochen
Posts: 48
Joined: 17 Apr 2016, 11:25

Re: #IfWinActive to child window

16 Dec 2017, 12:42

Hi Gregster,
Thanks a lot.
The msg message was just an example.

I want to create an action when "ClassNN: xMyProgram5100doc90121" of "MyProgram" is active.

The window "MyProgram" can be seen in Windows spy as well as on the screen.
When I call another function of "MyProgram" another window with another title is opened, but it is not mentioned in Windows Spy, just another ClassNN is displayed.
So the question was:
How can I tell autohotkey to act when the ClassNN is active?

I hope that is a little more detailed.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: #IfWinActive to child window

16 Dec 2017, 12:57

Hi Jochen,

A ClassNN serves to identify a control, not a window. It is typically the classname and instance number of the control - for instance: Edit_14, Static_2, Internet Explorer_Server1 etc.

Here's a example with notepad wich demonstrates how to make a context sensitive hotkey that matchs every window for a specific process but the main first one which first appears at program startup:

Code: Select all

run, notepad,,, PID ; run notepad and saves its process ID aka PID in 'PID' variable
WinWait, ahk_pid %PID% ; waits the window and set the lastfound window
ID := WinExist() ; when one use WinExit function without parameters, this one returns the ID of the lastfound window
return

#If ((WinActive("ahk_pid " . PID) <> ID) and ID) ; if the active window belongs to the process whose PID is the content of 'PID' variable and this window is not the main window...
Enter::MsgBox,,,, 1
#If ; turns off context-sensitivity for subsequent hotkeys if any

[EDIT]My bad looks i misread what you are exactly looking for. If you want to match a window which belongs to a specific process and has a specific control use something like the following instead:

Code: Select all

run, notepad,,, PID
WinWait, ahk_pid %PID%
ID := WinExist()
return

#If (WinActive("ahk_pid " . PID) and windowHasControl("ComboLBox3")) ;  ComboLBox3 the classNN of a control in the 'select font' child window of notepad
Enter::MsgBox,,,, 1
#If ; turns off context-sensitivity for subsequent hotkeys if any


windowHasControl(__classNN, __winTiitle:="") {
static __dummy := "$%µ&£"
WinGet, __list, ControlList, % __winTiitle ; retrieves a list of all the controls which belong to the specified window (here the lastfond one if unspecified)
return InStr(StrReplace(__list . "`n", "`n", __dummy), __classNN . __dummy)
}
Hope this helps
my scripts
Jochen
Posts: 48
Joined: 17 Apr 2016, 11:25

Re: #IfWinActive to child window

16 Dec 2017, 13:43

Hi A_AhkUser,
Thank you, you gave me someting to bite ;-)!
I will work on it.
Merci beaucoup!
Jochen
Posts: 48
Joined: 17 Apr 2016, 11:25

Re: #IfWinActive to child window

16 Dec 2017, 14:40

I tried around a little bit.
For once ist works fine, but...

Follwing problems:
1. The function should be usable, too if the program ist already running.
2. The function should be usable every time the mouse is inside the specific window control.

Perhaps there is a way to change a window (with a window title) in a way it is "really" displayed (like a title in windows Spy)?
In this case I could solve all I want...

Or perhaps it could be a way to wait for a window with a certain visible text and THAN react if you press ENTER?

sigh...
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: #IfWinActive to child window

16 Dec 2017, 18:15

I am at a loss to understand what you trying to achieve exactly. But if think if finally figured it out. However, what have you in mind by 'mouse is inside', the fact that the control is focused or that the mouse is over it? When in doubt, here's a example of a context-sensitive hotkey that performs depending on whether or not the mouse is over a specific control.

Code: Select all

#If MouseIsOver("Edit1", "ahk_exe notepad.exe")
; #If MouseIsOver("Edit1") ; omit the winTitle param to make it work with all windows instead
Enter::MsgBox,,, test, 1
#If

mouseIsOver(__classNN, __winTitle:="") {
    MouseGetPos,,, __window, __control, 1
return WinExist(__winTitle . " ahk_id " . __window) and (__control == __classNN)
} ; from the #1 example of #If documentation: https://www.autohotkey.com/docs/commands/_If.htm
If you want to determine if a specific control is focused instead, implement ControlGetFocus instead.

Btw, since you asked for it, if you want to change the title of the window, consider using WinSetTitle.
Jochen wrote:Merci beaucoup!
Je t'en prie. N'hésite pas si t'as besoin d'aide ;)
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, arcylix, drani, Google [Bot], Rohwedder and 209 guests