onevent confusion

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
erikforeman
Newbie
Posts: 6
Joined: Thu Apr 10, 2008 6:20 pm

onevent confusion

Post by erikforeman » Thu Apr 10, 2008 10:36 pm

I have two onevent's that notice when two different window titles open. the object is to hit the enter key when the window opens
Code:
OnEvent>WINDOW_OPEN,Information,1,Simple,Information
OnEvent>WINDOW_OPEN,Warning,1,Simple,Warning

WaitWindowOpen>Startup Options

Exit

SRT>Simple
SetFocus>%Simple_Var_1%*
MessageModal>Window Closer
Wait>.5
Press Enter
Wait>.5
Let>Simple_Var_1=
End>Simple

There are sometimes up to 2 Warning windows that show up before the Information Window comes opens The Warning windows are never closed the message never comes up in the Simple subroutine. Yet Information window works perfectly every time.

Help?
I tried
OnEvent>WINDOW_OPEN,Warning,2,Simple,Warning
no effect
I tried
OnEvent>WINDOW_OPEN,Warning,1,Simple,Warning
OnEvent>WINDOW_OPEN,Information,1,Simple,Information
no effect

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Apr 11, 2008 2:03 am

Your syntax is not correct. You can't pass values to the subroutine in the onevent. The easiest thing from the way you've written this might be to create two subroutines that each call the "simple" subroutine.

OnEvent>WINDOW_OPEN,Information,1,Simple1
OnEvent>WINDOW_OPEN,Warning,1,Simple2

WaitWindowOpen>Startup Options

Exit

SRT>Simple1
Gosub>simple,Information
END>Simple1

SRT>Simple2
Gosub>simple,Warning
END>Simple2

SRT>Simple
SetFocus>%Simple_Var_1%*
MessageModal>Window Closer
Wait>.5
Press Enter
Wait>.5
Let>Simple_Var_1=
End>Simple

erikforeman
Newbie
Posts: 6
Joined: Thu Apr 10, 2008 6:20 pm

I can

Post by erikforeman » Fri Apr 11, 2008 3:50 pm

I successfully pass the paramater to the subroutine in the information onevent. and even if I take that part out there is no change to the way the script runs. Warning still does not come up. I put a message modal in the SRT>Simple so I can see if it is even called. Warning never calls the subroutine. Information always calls it and passes the parameter correctly each time.

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Apr 11, 2008 6:12 pm

I'm surprised. And I stand corrected.

I tested your script and found that indeed parameters CAN be passed to a subroutine through onevent. I don't have your windows to test with so I used notepad and excel and the following script works. As I open excel or notepad a message pops up with excel or notepad in the message. After I close the message the excel or notepad window is closed and the script hums along waiting for me to open either excel or notepad and the process starts again.

Code: Select all

OnEvent>WINDOW_OPEN,NotePad*,1,Simple,Notepad
OnEvent>WINDOW_OPEN,Excel*,1,Simple,Excel

Label>Loop
Wait>0.01
Goto>Loop

SRT>Simple

MessageModal>Window Closer %Simple_Var_1%
SetFocus>%Simple_Var_1%*
Wait>1
Press Alt
Press F4
Release Alt
Let>Simple_Var_1=
End>Simple
My next thought would be that you need an asterisk in the window name parameter for the Warning window OnEvent line.

OnEvent>WINDOW_OPEN,Warning*,1,Simple,Warning

erikforeman
Newbie
Posts: 6
Joined: Thu Apr 10, 2008 6:20 pm

Child Window

Post by erikforeman » Fri Apr 18, 2008 11:00 pm

the suggestion is not working. The only thing I can figure is the difference bbtween these two windows is the one that is not being recognized "Warning" is a child window while the one that is being recognized "Information" is a standalone application window. could this be the source of my problem why onevent>Window_Open does not notice the Warning window at all?

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sat Apr 19, 2008 2:38 am

Have you tried experimenting with the WF_TYPE portion of the Window_Open OnEvent> along with the added asterisk?

Let>WF_TYPE=0 - No Child Windows
Let>WF_TYPE=1 - ALL Windows (Default)
Let>WF_TYPE=2 - Visible Windows Only
Let>WF_TYPE=3 - Child Windows Only

For Example:
OnEvent>WINDOW_OPEN,Warning,0,Simple,Warning*
or
OnEvent>WINDOW_OPEN,Warning,1,Simple,Warning*
or
OnEvent>WINDOW_OPEN,Warning,2,Simple,Warning*
or
OnEvent>WINDOW_OPEN,Warning,3,Simple,Warning*

erikforeman
Newbie
Posts: 6
Joined: Thu Apr 10, 2008 6:20 pm

Post by erikforeman » Mon Apr 21, 2008 3:58 pm

I have not tried setting it as 3 child window only. I tried 2 and 1. I thought if it was visible I should not need to use 3. The subroutine is not even getting called when the Warning window opens. I can try 3 and see if it makes a difference.

User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Post by Djek » Mon Apr 21, 2008 9:57 pm

hmmm... i get similar effects over here,
(with different windows)
The tought came up to me:
could it be possible that while de srt is running, the onevent gets another trigger to start another srt ?
Then its just like de onevents get a trigger from a non-existent window...

erikforeman
Newbie
Posts: 6
Joined: Thu Apr 10, 2008 6:20 pm

Post by erikforeman » Mon Apr 21, 2008 10:03 pm

If my subroutine was being called at all by anything the messagemodal would come up. Since it is not coming up at all I would say nothing is calling it.

User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Post by Djek » Mon Apr 21, 2008 10:31 pm

done some testing,
I definitly see that the srt is beeing triggerd twice!
Try to put WriteLn>c:\onevent.txt,result, %TIME% simple 2
instead of the messagemodal, and you'll be surprised !

here's my test:

Code: Select all

OnEvent>WINDOW_OPEN,Naamlo*,1,Simple1
OnEvent>WINDOW_OPEN,Microsoft Excel*,1,Simple2

rem Naalo* is Notepad default
rem Microsoft Excel* is Microsoft Excel new map

Label>Loop
Wait>0.01
GetTime>time
Goto>Loop

SRT>Simple1
WriteLn>c:\onevent.txt,result, %TIME% SIMPLE 1
wait>0.2
SetFocus>Naamlo*
Wait>0.2
Press Alt
Press F4
Release Alt
End>Simple1

SRT>Simple2
WriteLn>c:\onevent.txt,result, %TIME% simple 2
wait>1
SetFocus>Microsoft Excel*
Wait>0.2
Press Alt
Press F4
Release Alt
End>Simple2

if i open excel the srt is being called twice.

Or is it this late hour that i'm missing something?

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Apr 22, 2008 4:43 am

Erik,
Can you run the following script while your warning window is visible? Look for the name "Warning" in the list. Its possible that the window's name is not "Warning" at its creation. The window may be created with some other title and the title gets changed to "Warning".

Code: Select all

GetWindowList>list
WriteLn>c:\Windowlist.txt,wres,%list%
Run>notepad c:\Windowlist.txt
=====================================

Djek,
I think what you're seeing is the Onevent catching the window still open for a moment after the subroutine closes the window and finishes. Pressing Ctrl+F4 will close a window, but it will take a fraction of a second for the Operating system and the computer to respond. That fraction of a second is enough time for the OnEvent to trigger the Subroutine a second time.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Apr 22, 2008 4:50 am

Djek,
I think what you're seeing is the Onevent catching the window still open for a moment after the subroutine closes the window and finishes. Pressing Ctrl+F4 will close a window, but it will take a fraction of a second for the Operating system and the computer to respond. That fraction of a second is enough time for the OnEvent to trigger the Subroutine a second time.
Correct. Add this line to the end of the Subroutine:

WaitWindowClosed>Microsoft Excel*
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

erikforeman
Newbie
Posts: 6
Joined: Thu Apr 10, 2008 6:20 pm

JRL it was run

Post by erikforeman » Tue Apr 22, 2008 3:27 pm

I ran the script as you suggested and the word Warning was in the list there were no pre or trailing characters. I was hoping you were on to something there.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts