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!
#IfWinActive to child window
Re: #IfWinActive to child window
hmmm. is that question too stupid?
Please don´t let me die ignorant, any hint is welcome!
Please don´t let me die ignorant, any hint is welcome!
Re: #IfWinActive to child window
If, by "return", you mean the Enter key, you should change it to Enter. "Return" is a command used in functions and subroutines.
Re: #IfWinActive to child window
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!
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!
Re: #IfWinActive to child window
#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.
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.
Re: #IfWinActive to child window
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.
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.
Re: #IfWinActive to child window
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:
[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:
Hope this helps
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)
}
Re: #IfWinActive to child window
Hi A_AhkUser,
Thank you, you gave me someting to bite !
I will work on it.
Merci beaucoup!
Thank you, you gave me someting to bite !
I will work on it.
Merci beaucoup!
Re: #IfWinActive to child window
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...
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...
Re: #IfWinActive to child window
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.
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.
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
Btw, since you asked for it, if you want to change the title of the window, consider using WinSetTitle.
Je t'en prie. N'hésite pas si t'as besoin d'aideJochen wrote:Merci beaucoup!