I would like to set up a script to click an application button when it appears.
The button only appears in the application at a random time or event and the application may be mimimised at the time. I want to know how if possible this can be done.
I will call my application tester.exe (i can substitute real name later)
the button has the text 'REMINDER' and will appear randomly and once clicked the button will be hidden from the application until next time. So I guess there would be some test to see if a button is not hidden and then to hotkey the mouse click
PS The script needs to be in a loop so that it can detect the REMINDER button for a number of times not just one time only.
To recap
The application will run minimized,
The REMINDER button will randomly be available
Need to be able to click the REMINDER button and then wait until next time the button is shown

Waiting for a button
Started by
lesjar
, Jun 07 2010 12:46 PM
3 replies to this topic
#1
-
Posted 07 June 2010 - 12:46 PM

Welcome,
You did not supply code
so I assume its something like this your after?
I used 2 settimer threads.
The 1st to watch the button,
the 2nd to spawn the button.
The window with the button is spawned at random intervils.
The script watches for the buttons handle ( control hwnd )
which is unique everytime and a reliable approach.
Once the button spawns and is found,
Its unique handle is clicked using control click.
Although for this example the buttoned window is visible,
I added the detecthiddenwindows directive.
This ensures the button would be clicked
whether visible, minimized or even hidden.
hth
You did not supply code
so I assume its something like this your after?
cnt:=20 detecthiddenwindows, on settimer, watchButton, on settimer, spawnButton, % rnd( 1, 5 ) return watchButton: controlGet, btnHwnd, Hwnd,, REMINDER, buttonWindow coordMode, tooltip, screen tooltip % ( !( btnHwnd ) ? "Waiting for button to appear!" : "Found button handle: " btnHwnd . "`nWill click in " cnt-- ),10 , 10 if ( ( btnHwnd ) && !( cnt+1 ) ) { settimer, watchButton, Off controlClick,, % "ahk_id " btnHwnd } return spawnButton: gui, add, button, gcloseUI, REMINDER gui, show,, buttonWindow settimer, spawnButton, Off return closeUI: gui, Destroy exitApp rnd( mN, mX ) { random, rndNm, % ( mN*1000 ), % ( mX*1000 ) return % rndNm }For the repetative search,
I used 2 settimer threads.
The 1st to watch the button,
the 2nd to spawn the button.
The window with the button is spawned at random intervils.
The script watches for the buttons handle ( control hwnd )
which is unique everytime and a reliable approach.
Once the button spawns and is found,
Its unique handle is clicked using control click.
Although for this example the buttoned window is visible,
I added the detecthiddenwindows directive.
This ensures the button would be clicked
whether visible, minimized or even hidden.
hth
#2
-
Posted 07 June 2010 - 01:46 PM

don't duplicate, iterate!
The only thing is that another application may be running i.e. outlook to receive an e-mail from my TESTER.EXE application. Thus I need to only apply the code to the TESTER.EXE which would be running minimised
#3
-
Posted 07 June 2010 - 01:53 PM

The controlget hwnd ( handle ) in the watchButton thread ( on line 7 )The only thing is that another application may be running i.e. outlook to receive an e-mail from my TESTER.EXE application. Thus I need to only apply the code to the TESTER.EXE which would be running minimised
will only look for the "REMINDER" button on the GUI.
Note the different hwnd displayed in the tooltip message
each time a new "REMINDER" button is spawned.
Heres another example
with a more repetative approach:
cnt:=20, i:=!i settimer, watchButton, on settimer, spawnButton, % rnd( 1, 5 ) return watchButton: controlGet, btnHwnd, Hwnd,, REMINDER, [color=purple]buttonWindow[/color] ; hwnd only for classNN on GUI coordMode, tooltip, screen tooltip % ( !( btnHwnd ) ? "Waiting for button to appear!" : "Found button handle: " btnHwnd . "`nWill click in " cnt-- ),10 , 10 if ( ( btnHwnd ) && !( cnt+1 ) ) { setcontroldelay, 100 settimer, watchButton, Off while ( btnHwnd ) controlClick,, % "ahk_id " btnHwnd,,,, NA } else if ( i>5 ) exitApp return spawnButton: gui, add, button, gcloseUI, REMINDER gui, show,, buttonWindow settimer, spawnButton, Off return closeUI: gui, Destroy cnt:=20, btnHwnd:="", i++ settimer, watchButton, on settimer, spawnButton, % rnd( 1, 5 ) rnd( mN, mX ) { random, rndNm, % ( mN*1000 ), % ( mX*1000 ) return % rndNm }Restarts search ( 6 times or if i>5 ) whether the button is clicked by script
or manually by user ( try clicking too see what I mean ).
htms
#4
-
Posted 07 June 2010 - 02:41 PM

don't duplicate, iterate!