Hello Fellow AHK friends!
I have been on the hunt to find a working functioning method to execute my idea.
GOAL: Wait for a classNN to exist, then continue.
NOTE: This isn't my actual code for what I am trying to do, all of that is stored at work. This is just an example.
My code that isn't working.....below.
------------------------------
-----------------------------
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance,Force
home::
;not sure how to add a loop in here, but I think I need one in order for it to wait for class
#If WinExist("ahk_class button1")
{
ControlClick, Button1, MacroGamer, , Left, 1
sleep, 10
return
}
IfWinNotExist("ahk_class button1") ;this part I don't necessarily need, it's just for me to test if it worked or not. "button1" WILL exist, just needs to wait for it.
{
Msgbox not found
}
return
---------------------------
---------------------------
So while this code may get working, I need to also comment that the program I'm using at work has an environment inside of it. So to have WinWaitActive, yadaya - won't work. This is why I want to wait for a class. I am closing accounts at work.
I hope this is enough information and my goal is clear. Any help is appreciated.
Thank you,
Vh_
If WinExist, ClassNN Topic is solved
Re: If WinExist, ClassNN
You might be interested in SetTimer, eg,
Code: Select all
#Persistent
SetTimer, checkIfClassExist, 100
return
checkIfClassExist:
If WinExist("ahk_class button1")
{
ControlClick, Button1, MacroGamer, , Left, 1
sleep, 10
return
}
else ;this part I don't necessarily need, it's just for me to test if it worked or not. "button1" WILL exist, just needs to wait for it.
{
Msgbox not found
}
return
Re: If WinExist, ClassNN
this code doesn't work :/Helgef wrote:You might be interested in SetTimer, eg,Code: Select all
#Persistent SetTimer, checkIfClassExist, 100 return checkIfClassExist: If WinExist("ahk_class button1") { ControlClick, Button1, MacroGamer, , Left, 1 sleep, 10 return } else ;this part I don't necessarily need, it's just for me to test if it worked or not. "button1" WILL exist, just needs to wait for it. { Msgbox not found } return
Re: If WinExist, ClassNN
Still hops directly to msgbox when Button1 is present
Re: If WinExist, ClassNN
I read these docs and can't seemingly connect the dots.. can you give an example please?
Thank you!
Thank you!
Re: If WinExist, ClassNN
My guess is, Button1 is the ClassNN of a control, not the window class of the window in which the control resides. So, instead of WinExist("ahk_class Button1"), you migth identify the window which holds the control (Button1) by other means, eg, open WindowSpy and hover the mouse over the window, at the top, you'll see ahk_class something, use that instead, or ahk_exe something.exe. Here is an example,
Good luck.
Good luck.
Re: If WinExist, ClassNN
Thanks for the reply!
Here is the thing.While I can tell it to identify with the program name, my purpose is for a program at work that has an environment inside of the window. So the program will exist. I want it to execute upon class existence rather window exist. does that make sense?
Here is the thing.While I can tell it to identify with the program name, my purpose is for a program at work that has an environment inside of the window. So the program will exist. I want it to execute upon class existence rather window exist. does that make sense?
Re: If WinExist, ClassNN
Consider this,
You can use WinGet to get a list of controls for a window of your choise.
Code: Select all
Gui, add, button,, hi
Gui show
MsgBox, % WinExist("ahk_class Button1")
ExitApp
Re: If WinExist, ClassNN
Code: Select all
q:: ;check control (ClassNN) exists
;try this on Notepad and on Notepad's Find dialog
ControlGet, hCtl, Hwnd, , Button1, A
if hCtl
MsgBox % "control exists"
else
MsgBox % "control doesn't exist"
Return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: If WinExist, ClassNN
Im sorry jeeswg, control existed in either state.. I am starting to think this is not possible with AHK.
Re: If WinExist, ClassNN
ok guys. here is the actual code. See line 42 with ControlClick
---------------------------------------------------------------------------------
---------------------------------------------------------------------------
----------------------------------------------------------------------
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance,Force
Gui, +Caption
Gui, +AlwaysOnTop
Gui, Add, Text, x10 y5 +BackgroundTrans cWhite, Status ;add colored text in options, (after x/y coord. eg, cBlue)
Gui, Add, DropDownList, x10 y20 w180 h100 vStatus, CLOSED|INACTIVE|ACTIVE|PENDING
Gui, Add, Text, x10 y45 +BackgroundTrans cWhite, Note
Gui, Add, Edit, x10 y60 w180 h50 vMyEdit
Gui, Add, Text, x10 y114 +BackgroundTrans cWhite, Bind Key
Gui, Add, Hotkey, x10 y+4 w180 h20, vChosenHotkey gHotkey
Gui, Add, Text, x10 y160 +BackgroundTrans cWhite, Run without key (optional)
Gui, Add, Button, x10 y175 w180 h30 gOK , Run
Gui, Color, 474747
Gui, Show, w200 h220, Assistant ;Window title is Account Assistant
return
; Labels
;---------------
;----------------------
;-------------------------------
OK:
Gui, Submit, NoHide
SetTitleMatchMode, 2
WinActivate, PAYCheque
IfWinActive, PAYCheque
{
ControlClick, ThunderRT6ListBox1 ;This is where I want it to wait for the class to exist before continuing
sleep, 1
if (Status = "CLOSED")
{
Send, C
} else if (Status = "INACTIVE") {
Send, I
} else if (Status = "ACTIVE") {
Send, A
else if (Status = "PENDING") {
Send, P
}
Send, {tab}
sleep, 1
Send, %MyEdit%
}
return
Hotkey:
If (ChosenHotkey)
{
Hotkey, %ChosenHotkey%, OK
}
return
---------------------------------------------------------------------------------
---------------------------------------------------------------------------
----------------------------------------------------------------------
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance,Force
Gui, +Caption
Gui, +AlwaysOnTop
Gui, Add, Text, x10 y5 +BackgroundTrans cWhite, Status ;add colored text in options, (after x/y coord. eg, cBlue)
Gui, Add, DropDownList, x10 y20 w180 h100 vStatus, CLOSED|INACTIVE|ACTIVE|PENDING
Gui, Add, Text, x10 y45 +BackgroundTrans cWhite, Note
Gui, Add, Edit, x10 y60 w180 h50 vMyEdit
Gui, Add, Text, x10 y114 +BackgroundTrans cWhite, Bind Key
Gui, Add, Hotkey, x10 y+4 w180 h20, vChosenHotkey gHotkey
Gui, Add, Text, x10 y160 +BackgroundTrans cWhite, Run without key (optional)
Gui, Add, Button, x10 y175 w180 h30 gOK , Run
Gui, Color, 474747
Gui, Show, w200 h220, Assistant ;Window title is Account Assistant
return
; Labels
;---------------
;----------------------
;-------------------------------
OK:
Gui, Submit, NoHide
SetTitleMatchMode, 2
WinActivate, PAYCheque
IfWinActive, PAYCheque
{
ControlClick, ThunderRT6ListBox1 ;This is where I want it to wait for the class to exist before continuing
sleep, 1
if (Status = "CLOSED")
{
Send, C
} else if (Status = "INACTIVE") {
Send, I
} else if (Status = "ACTIVE") {
Send, A
else if (Status = "PENDING") {
Send, P
}
Send, {tab}
sleep, 1
Send, %MyEdit%
}
return
Hotkey:
If (ChosenHotkey)
{
Hotkey, %ChosenHotkey%, OK
}
return
Re: If WinExist, ClassNN Topic is solved
as mentioned on irc (for others to see), just toss in
where "INSERT THE WINDOW TITLE HERE" is the ahk_class (as shown by helgef) or the actual title, if it never changes
Code: Select all
loop
{
sleep, 50
ControlGet, hCtl, Hwnd, , ThunderRT6ListBox1, INSERT THE WINDOW TITLE HERE
}
until (errorlevel=0)
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
*poke*
Is it December 21, 2012 yet?
-
- Posts: 302
- Joined: 05 Feb 2017, 00:03
Re: If WinExist, ClassNN
It looks to me you could use the example code jeeswg gave to loop check if the control exists before continuing.
something like:
I'm not sure this is the best way to accomplish what you want but it should work.
**Edit I guess I'm a tad bit too slow.
something like:
Code: Select all
loop
{
ControlGet, hCtl, Hwnd, , ThunderRT6ListBox1, A ; (If its not in the active window change 'A' to be the window it is in, either its name or class.)
if hCtl
Break
}
ControlClick, ThunderRT6ListBox1
**Edit I guess I'm a tad bit too slow.
Re: If WinExist, ClassNN
You could also check if the control is enabled or visible.
Code: Select all
q:: ;check if control exists/is enabled/is visible (+ get styles)
vCtlClassNN := "Button1"
WinGet, hWnd, ID, A
ControlGet, hCtl, Hwnd, , % vCtlClassNN, % "ahk_id " hWnd
ControlGet, vIsEnabled, Enabled, , % vCtlClassNN, % "ahk_id " hWnd
ControlGet, vIsVisible, Visible, , % vCtlClassNN, % "ahk_id " hWnd
ControlGet, vCtlStyle, Style, , % vCtlClassNN, % "ahk_id " hWnd
ControlGet, vCtlExStyle, ExStyle, , % vCtlClassNN, % "ahk_id " hWnd
vOutput := hCtl " -- " vIsEnabled " -- " vIsVisible " -- " vCtlStyle " -- " vCtlExStyle
Clipboard := vOutput
MsgBox % vOutput
Return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: If WinExist, ClassNN
Ladies & Gentlemen. I must extend great appreciation for joining me on this quest. I deem this solved. Thank you for your patience and EXCELLENT INPUT, ALL!
Vh
Vh