jonnym Posted May 24, 2010 Share Posted May 24, 2010 Hello, I created a script and I want it to "beep" if the script stops because of an error if the window that should be active is not active. I'm very new to Autoit and here is what I wrote: HotKeySet("{ESC}","Quit") ;Press ESC key to quit Func Quit() Exit EndFunc sleep (2000) For $i = 1 to 1000 Step 1 Mouseclick ("left" ,76,122,1) ;pica tab WBI WinWaitActive ("wbi") If @error = 0 Then Beep(500, 1000) Endif MouseClick ("left",Random(325,385,1),Random(155,157,1)) ;pica site WBI MouseClick ("left",Random(325,385,1),Random(163,167,1)) ;pica site WBI MouseClick ("left",Random(325,385,1),Random(168,173,1)) ;pica site WBI MouseClick ("left",318,117,1) ;pica tab TTT Sleep (random(1521,2421,1)) MouseClick ("left",Random(325,385,1),Random(155,157,1)) ;pica next site TTT MouseClick ("left",Random(325,385,1),Random(163,167,1)) ;pica next site TTT MouseClick ("left",Random(325,385,1),Random(168,173,1)) ;pica next site TTT MouseClick ("left",560,120,1) ;pica tab LOT Sleep (random(1354,3120,1)) MouseClick ("left",1015,697,1) ;pica emblema der. LOT MouseClick ("left",276,680,1) ;pica emblema izq. LOT MouseClick ("left",801,120,1) ;pica tab HW Sleep (random(1455,2612,1)) MouseClick ("left",Random(219,257,1),Random(157,182,1)) ;pica click here arriba HW MouseClick ("left",1207,122,1) ;cierra tab casual MouseClick ("left",Random(219,257,1),Random(672,696,1)) ;pica click here abajo HW MouseClick ("left",1207,122,1) ;cierra tab casual Sleep (random(1812,2525,1)) next The script works but it does not beep if the window is not active. Can anyone help, please? Link to comment Share on other sites More sharing options...
jaberwacky Posted May 24, 2010 Share Posted May 24, 2010 Looks good but you're testing @error. Look up WinWaitActive in the helpfile to see how to test the return value. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
JohnOne Posted May 24, 2010 Share Posted May 24, 2010 Also If your window does not become active then you still wont hear a beep after checking for its return value, because It wont return until the window is active. So there is another reason to read up on the function in the helpfile .. param timeout AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jonnym Posted May 24, 2010 Author Share Posted May 24, 2010 Ok, I just checked the WinWaitActive and I added 5 seconds as a timeout. So now if the window is not active the return value after 5 secs should be 0 It still does not beep HotKeySet("{ESC}","Quit") ;Press ESC key to quit Func Quit() Exit EndFunc sleep (2000) For $i = 1 to 1000 Step 1 Mouseclick ("left" ,76,122,1) ;pica tab WBI WinWaitActive ("wbi",5) If @error = 0 Then Beep(500, 1000) Endif MouseClick ("left",Random(325,385,1),Random(155,157,1)) ;pica site WBI MouseClick ("left",Random(325,385,1),Random(163,167,1)) ;pica site WBI MouseClick ("left",Random(325,385,1),Random(168,173,1)) ;pica site WBI MouseClick ("left",318,117,1) ;pica tab TTT Sleep (random(1521,2421,1)) MouseClick ("left",Random(325,385,1),Random(155,157,1)) ;pica next site TTT MouseClick ("left",Random(325,385,1),Random(163,167,1)) ;pica next site TTT MouseClick ("left",Random(325,385,1),Random(168,173,1)) ;pica next site TTT MouseClick ("left",560,120,1) ;pica tab LOT Sleep (random(1354,3120,1)) MouseClick ("left",1015,697,1) ;pica emblema der. LOT MouseClick ("left",276,680,1) ;pica emblema izq. LOT MouseClick ("left",801,120,1) ;pica tab HW Sleep (random(1455,2612,1)) MouseClick ("left",Random(219,257,1),Random(157,182,1)) ;pica click here arriba HW MouseClick ("left",1207,122,1) ;cierra tab casual MouseClick ("left",Random(219,257,1),Random(672,696,1)) ;pica click here abajo HW MouseClick ("left",1207,122,1) ;cierra tab casual Sleep (random(1812,2525,1)) next Link to comment Share on other sites More sharing options...
JohnOne Posted May 24, 2010 Share Posted May 24, 2010 (edited) You did not fully understand the help file, winwaitactive does not set @error try replacing WinWaitActive ("wbi",5) If @error = 0 Then Beep(500, 1000) Endif With If Not WinWaitActive ("wbi","",5) Then Beep(500, 1000) EndIf Also notice you have the timeout in the wrong place Edited May 24, 2010 by JohnOne AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jonnym Posted May 24, 2010 Author Share Posted May 24, 2010 Also If your window does not become active then you still wont hear a beep after checking for its return value, because It wont return until the window is active.So there is another reason to read up on the function in the helpfile .. param timeoutOk, this sounds logic Link to comment Share on other sites More sharing options...
jonnym Posted May 24, 2010 Author Share Posted May 24, 2010 You did not fully understand the help file, winwaitactive does not set @errortry replacingWinWaitActive ("wbi",5)If @error = 0 Then Beep(500, 1000)EndifWithIf Not WinWaitActive ("wbi","",5) Then Beep(500, 1000)EndIfAlso notice you have the timeout in the wrong placeok..., thanks. I'll check this as well Link to comment Share on other sites More sharing options...
CodyBarrett Posted May 24, 2010 Share Posted May 24, 2010 (without looking at the code) Does your computers Beep Speaker work? maybe that would be the problem. [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
jonnym Posted May 25, 2010 Author Share Posted May 25, 2010 (edited) Yes it does work. I've tested it using just the beep command alone. So now the script stops if the window is not active but still I get no "beep" when this happens.... HotKeySet("{ESC}","Quit") ;Press ESC key to quit Func Quit() Exit EndFunc sleep (2000) For $i = 1 to 1000 Step 1 Mouseclick ("left" ,76,122,1) ;pica tab WBI WinWaitActive ("Wbi") If Not WinWaitActive ("Wbi","",5) Then ;espera vantana activa beep (500, 1000) ;pica si ventana no activa EndIf MouseClick ("left",Random(325,385,1),Random(155,157,1)) ;pica next site WBI MouseClick ("left",Random(325,385,1),Random(163,167,1)) ;pica next site WBI MouseClick ("left",Random(325,385,1),Random(168,173,1)) ;pica next site WBI Edited May 25, 2010 by jonnym Link to comment Share on other sites More sharing options...
JohnOne Posted May 25, 2010 Share Posted May 25, 2010 Remove this line WinWaitActive ("Wbi") AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jonnym Posted May 25, 2010 Author Share Posted May 25, 2010 If I remove that line the script does not stop when the "wbi" window isn't active. Link to comment Share on other sites More sharing options...
Affe Posted May 25, 2010 Share Posted May 25, 2010 (edited) If I remove that line the script does not stop when the "wbi" window isn't active. Currently, since you still have the first line, it's waiting on the window to be active and not proceeding to the If statement. Is there a reason you don't just activate the window? HotKeySet("{ESC}","Quit") ;Press ESC key to quit Func Quit() Exit EndFunc sleep (2000) ;NOTE: This sleep only pauses your script at the beginning, and is probably not necessary For $i = 1 to 1000 Step 1 ;NOTE: You don't need the "Step" if you are moving by increments of 1 Mouseclick ("left" ,76,122,1) ;pica tab WBI While 1 ;continue loop until WBI win exists If WinExists("Wbi") Then WinActivate("Wbi") WinWaitActive ("Wbi") ExitLoop Else beep(500, 1000) ;Window does not exist ;you could add further instruction here to re-try picking the WBI tab, but should re-activate the previous window Mouseclick ("left" ,76,122,1) ;pica tab WBI Endif WEnd MouseClick ("left",Random(325,385,1),Random(155,157,1)) ;pica next site WBI MouseClick ("left",Random(325,385,1),Random(163,167,1)) ;pica next site WBI MouseClick ("left",Random(325,385,1),Random(168,173,1)) ;pica next site WBI Edited May 25, 2010 by Affe [center][/center] Link to comment Share on other sites More sharing options...
JohnOne Posted May 25, 2010 Share Posted May 25, 2010 If I remove that line the script does not stop when the "wbi" window isn't active.But it does beep ?So put some other code in the If...EndIf condition, either replacing beep or underneath it, to have it do what you want.The only reason your script was stopping in the first place was because of an error in your coding. AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jonnym Posted May 25, 2010 Author Share Posted May 25, 2010 Ok... There is a problem here: I've not explained what the script does. So I have a web browser with 4 open taps. The first tab is the "wbi" tab. Now I want the script to click on certain location on the diferent tabs and start all over again with the "wbi" tab 1000 times. Ok, everything workes fine so far. The problem now is that sometimes because of an inapropiate mouseclick or for any other reason a new window opens and gets active. Now when I want the "wbi" tab to get active again to restart all the process it's not possible because the other active window is in its way. In this case I want the script to stop and beep so I can correct the error and restart the script; otherwise it will continue workin wihout doing anything. Link to comment Share on other sites More sharing options...
Affe Posted May 25, 2010 Share Posted May 25, 2010 (edited) Ok... There is a problem here: I've not explained what the script does.So I have a web browser with 4 open taps. The first tab is the "wbi" tab. Now I want the script to click on certain location on the diferent tabs and start all over again with the "wbi" tab 1000 times. Ok, everything workes fine so far. The problem now is that sometimes because of an inapropiate mouseclick or for any other reason a new window opens and gets active. Now when I want the "wbi" tab to get active again to restart all the process it's not possible because the other active window is in its way. In this case I want the script to stop and beep so I can correct the error and restart the script; otherwise it will continue workin wihout doing anything.Did my above example not help? I had written it to automate the process of re-activating the WBI tab, removing the need for a "beep" altogether.If the problem is that the WBI window now has an "unknown" title, you should try using _IEAttach() to have a sure handle on the window, and getting the title of the window with _IEPropertyGet().If you are using a browser other than IE, there are UDF's for FireFox as well. I'm unsure of support for other browsers. Edited May 25, 2010 by Affe [center][/center] Link to comment Share on other sites More sharing options...
jonnym Posted May 25, 2010 Author Share Posted May 25, 2010 But it does beep ?So put some other code in the If...EndIf condition, either replacing beep or underneath it, to have it do what you want.The only reason your script was stopping in the first place was because of an error in your coding.No, it doesn't... Link to comment Share on other sites More sharing options...
jonnym Posted May 25, 2010 Author Share Posted May 25, 2010 Did my above example not help? I had written it to automate the process of re-activating the WBI tab, removing the need for a "beep" altogether.If the problem is that the WBI window now has an "unknown" title, you should try using _IEAttach() to have a sure handle on the window, and getting the title of the window with _IEPropertyGet().If you are using a browser other than IE, there are UDF's for FireFox as well. I'm unsure of support for other browsers.I've not been able to test it as I'm currently working. I'll check your code tomorrow. Thanks Link to comment Share on other sites More sharing options...
jonnym Posted May 26, 2010 Author Share Posted May 26, 2010 Currently, since you still have the first line, it's waiting on the window to be active and not proceeding to the If statement. Is there a reason you don't just activate the window? HotKeySet("{ESC}","Quit") ;Press ESC key to quit Func Quit() Exit EndFunc sleep (2000) ;NOTE: This sleep only pauses your script at the beginning, and is probably not necessary For $i = 1 to 1000 Step 1 ;NOTE: You don't need the "Step" if you are moving by increments of 1 Mouseclick ("left" ,76,122,1) ;pica tab WBI While 1 ;continue loop until WBI win exists If WinExists("Wbi") Then WinActivate("Wbi") WinWaitActive ("Wbi") ExitLoop Else beep(500, 1000) ;Window does not exist ;you could add further instruction here to re-try picking the WBI tab, but should re-activate the previous window Mouseclick ("left" ,76,122,1) ;pica tab WBI Endif WEnd MouseClick ("left",Random(325,385,1),Random(155,157,1)) ;pica next site WBI MouseClick ("left",Random(325,385,1),Random(163,167,1)) ;pica next site WBI MouseClick ("left",Random(325,385,1),Random(168,173,1)) ;pica next site WBI Ok, I've tested your code and yes! It works!! Great, thank you very much! And because of the loop it beeps until I correct the error. I just had to add a "sleep" after the first "MouseClick" because it kept beeping in every cycle. HotKeySet("{ESC}","Quit") ;Press ESC key to quit Func Quit() Exit EndFunc sleep (2000) ;NOTE: This sleep only pauses your script at the beginning, and is probably not necessary For $i = 1 to 1000 Step 1 ;NOTE: You don't need the "Step" if you are moving by increments of 1 Mouseclick ("left" ,76,122,1) ;pica tab WBI Sleep (1000) ; a little more time for the window to become active While 1 ;continue loop until WBI win exists If WinExists("Wbi") Then WinActivate("Wbi") WinWaitActive ("Wbi") ExitLoop Else beep(500, 1000) ;Window does not exist Mouseclick ("left" ,76,122,1) ;pica tab WBI Endif WEnd MouseClick ("left",Random(325,385,1),Random(155,157,1)) ;pica next site WBI MouseClick ("left",Random(325,385,1),Random(163,167,1)) ;pica next site WBI MouseClick ("left",Random(325,385,1),Random(168,173,1)) ;pica next site WBI Cool Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now