Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Detecting a popup window


  • Please log in to reply
9 replies to this topic
Lambrechtn
  • Guests
  • Last active:
  • Joined: --
Hi to the autohotkey community.

RANDOM INFO: (ignore as you wish :lol: )
I am trying to build an automated process, with at least 3 PC's. 2 PC's will control a machine each, and the third controls a robot and all scripthandling
I am using PSexec to transport scripts to my "machine PC's". On those Machine PC's there is a Program.
The program is an automated proces on its own allready, and every time it completes a run, it sends a popup message like : "Run succesfully competed". Then I have to push enter (default key is active, so no selecting of the popup is needed = I can use {ENTER} when it pops up)

PROBLEM:
The problem is that the popup message carries the same tag as the program in my case. I was thinking on using:

WinWait, ,GGG
Send, {ENTER}

My program is called GGG and the pop up window is called GGG too, I can't wait on that pop up -> If my program was called GXG and the popup GGG I could.

QUESTION:
Is there a workaround to this problem without using "advanced code" -> being screen capturing and comparing, or pixelchanging (for I have no clue to determin at what x:y coördinates my popup will appear)

MORE RANDOM INFO
FYI -> I'm using autohotkey for like 2 days now so I'm kinda new :oops:

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
for the WinWait command, also use the WinText paramater, which will narrow the WinWait command to only find your popup. The wintext should be something like Run Completed, or whatever your popup text is.

also, the window class might be different, so instead of WinTitle, you can use ahk_class (with the right window class for the popup).

Lambrechtn
  • Guests
  • Last active:
  • Joined: --
I will try out your suggestions first thing in the morning. Fast reply btw ^^

Eedis
  • Members
  • 1775 posts
  • Last active: Aug 14 2015 06:33 PM
  • Joined: 12 Jun 2009
Why don't you try using the window's ahk_class instead of the title?

Also look into the WinSetTitle. That may help to.
AutoHotkey state, the forum, Poly, and Drainx1. The short story.
I love my wife, my life, my atomic-match; for giving me the greatest gift a man could ask for, such a perfect and beautiful little girl.
9rjbjc.png

Lambrechtn
  • Guests
  • Last active:
  • Joined: --
Is it possible to add the handle as well?
I use the following right now in an example, with the last couple of lines being the important ones :). The handle in this particular example should be 7037C (captured with screenxscreenx[/url])

IfWinExist Untitled - Notepad	
	WinActivate
else
	Run Notepad

Sleep, 100
Send, Help, {SPACE}I{SPACE}Need{SPACE}Some{SPACE}Experience.
Sleep, 100
Send, {F10} ;here I am activating the Ctrl Commands
Send, {ALTDOWN}{F4}{ALTUP} ;closing notepad with keystrokes

WinWait, ahk_class #32770, 
WinActivate, Notepad, 
sleep 1000 ; to see what is happening 
Send, N


The following code contains the GUI is might use (or part of it). I might want to add 2 buttons more, later on (run pc1/run pc2). And maybe a small .ico of the company above the buttons. There isn't much underlying code yet because all hardware isn't in location yet, and the machines still have to work all day (manually).

Gui, font,, Arial
Gui Add, Button,w100 Default, &Run
Gui Add, Button,w100, &Botreset
Gui Add, Button,w100, &Stop

Gui, Show, , Auto-mate ; Applicationname
Gui, Color, 191970 ; Window Coloring  (191970 = hex color code)


return ; End of auto-execute section. The script is idle until the user does something.

; you might want to skip pressing this button unless you're controlling my 
; remote pc, or if you know what to change :D
ButtonRun:
	Msgbox, Running
	run C:\psexec \\pc14332.somecompany.local -u "SOMEWHERE\someuser" -p "somepassword" -s -i -c -f "C:\Documents and Settings\someperson\Desktop\test1.exe" 
						;running of test1.exe
	return

ButtonBotreset:
	Msgbox, Placing Bot at starting position
	return

ButtonStop:
	Msgbox, 4,, Are you sure you want to quit?

	IfMsgBox, No
		return
	IfMsgBox, Yes
		ExitApp
		return



Lambrechtn
  • Guests
  • Last active:
  • Joined: --
oh yes,

a small error :)

WinWait, ahk_class #32770, 
WinActivate
sleep 1000 ; to see what is happening 
Send, N 


Lambrechtn
  • Guests
  • Last active:
  • Joined: --
I keep on finding coding errors, made with autoscriptwriter :)
Send, {F4} ;closing notepad with keystrokes


Lambrechtn
  • Guests
  • Last active:
  • Joined: --
Man I need an account :oops:
there's probably the {ALT} missing now...

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
free to sign up?

In general, I now tell people to avoid the scriptwriter. You can learn AHK and make better code faster without it.

Lambrechtn
  • Members
  • 14 posts
  • Last active: Oct 20 2009 02:17 PM
  • Joined: 25 Sep 2009
-> lazybones

yeah, I don't use the scriptwriter anymore. ^^ Ik went on the "trial and error, error, error " method

I had a problem with the ahk_class, -> similar to my first problem with the wintitle :). This time the problem was with "Open File" and my "completed run" popup being the same class. I made it simple and started comparing the windowsize of the first ahk_class popup. (Atm Im checking for the size of the "Open File" window though.

QUESTION 2: I should probably loop the winwait ahk_class SunAwtDialog as well right? Otherwise If I get the right class with the wrong size, and then a wrong class with right size, the {ESC} command will still be executed, on the wrong window. = is solved

In the autrorun:
vROL = OPEN 567 293                           ; The wanted titlename and popupbox size is declared here,

for my loop:
Loop,                          ; this is an infinite loop unless "break" or "return" is encountered inside.
 {
     
 WinWait, ahk_class SunAwtDialog,
  WinActivate, ahk_class SunAwtDialog, 
  sleep, 100
 WinGetActiveStats, Title, Width, Height, X, Y
 If vROL = %Title% %Width% %Height%             ; ROL compared to the active window.
    {
     Sleep, 100
    Send, {Esc}
     Sleep, 100
    Gui, 2: Add, Text,, Popup detected!
     Gui, 2: Show, , Warning!
      Sleep, 1000
     Gui, 2: Destroy
    }
    Else
     return  
 }
 
return

NOW to the next question.... :twisted:
QUESTION 3:

I have a problem. AGAIN! This time I need help on the GUI. After I start my program -> click start , open my popup, and click close, I can't click start again... Allso I dont know how to relocate my buttons and picture, if you run the code you'll see the buttons being extremely liberal (left right?).



; PROGRAM
 Gui, Add, Picture, w64 h64, C:\Documents and Settings\lambresv\Desktop\Automate\BPS_Crop_design_SMALL.ico  ; for running the GUI on your PC, pick your own. ico file or delete this line
 Gui, Add, Button,w50, &OnTop
 Gui, Add, Button,w150 h50 Default, &Run
 Gui, Add, Button,w150 h50, &Stop
 Gui, Add, Button,w50, &Exit
 Gui, Show, , Auto-mate                         ; Applicationname.
 Gui, Color, 191970				            	; Window Coloring  (191970 = hex color code)
 WinSet, AlwaysOnTop, OFF, Auto-mate

vROL = OPEN 567 293                           ; The wanted titlename and popupbox size is declared here,

Return

;_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

ButtonOnTop:                                    ;Allways On Top Toggle

 WinSet, AlwaysOnTop, TOGGLE, Auto-mate

Return
;_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- 

ButtonStop:                                     ; The Stop Program
 
if  Rex = 1
{
 MsgBox, 4, Warning!, Are you sure you want to Stop? 
  
 IfMsgBox, YES
 {
 Gui, 2: Add, Text,, Stopping Program!
 Gui, 2: Show, , Warning!
 sleep, 1000
 Rex = 0
 Gui, 2: Destroy
 return
 }
}
 Else
 Return 
  
Return

;_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

ButtonRun:                                      ; The Run Program

Rex = 1

MsgBox, 4, Warning!, Do you want to start the program?
  
 IfMsgBox, NO
  Return
  
 Gui, 2: Add, Text, , Program running!			
  Gui, 2: Show, , Warning!
   Sleep, 1000
  Gui, 2: Destroy
   Sleep, 100
   
 Loop,                          ; this is an infinite loop unless "break" or "return" is encountered inside.
 {
     
 WinWait, ahk_class SunAwtDialog,
  WinActivate, ahk_class SunAwtDialog, 
  sleep, 100
 WinGetActiveStats, Title, Width, Height, X, Y
 MsgBox, , , %vROL% = %Title% %Width% %Height% ?
   If vROL = %Title% %Width% %Height%             ; ROL compared to the active window.
    {
     Sleep, 100
    Send, {Esc}
     Sleep, 100
    Gui, 2: Add, Text,, Popup detected!
     Gui, 2: Show, , Warning!
      Sleep, 1000
     Gui, 2: Destroy
    }
    Else
     return  
 }
 
return

;_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- 


ButtonExit:

IfEqual, rex, 0
 ExitApp
 
IfEqual, rex, 1
 Gui, 2: Add, Text,, Please Stop the program first !
     Gui, 2: Show, , Warning!
      Sleep, 1000
     Gui, 2: Destroy
 
return
 
;_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- 

GuiClose:

IfEqual, rex, 0
 ExitApp
 
IfEqual, rex, 1
Gui, 2: Add, Text,, Forcing close!
     Gui, 2: Show, , Warning!
      Sleep, 1000
     Gui, 2: Destroy
ExitApp

return

; END OF PROGRAM

PS: I started using SciTE because notepad makes me go blind.