Jump to content

About Beep


Recommended Posts

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

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

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

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 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

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

Ok, this sounds logic :idea:

Link to comment
Share on other sites

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

ok..., thanks. I'll check this as well :idea:

Link to comment
Share on other sites

(without looking at the code)

Does your computers Beep Speaker work? maybe that would be the problem.

Link to comment
Share on other sites

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 by jonnym
Link to comment
Share on other sites

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 by Affe

[center][/center]

Link to comment
Share on other sites

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

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

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 by Affe

[center][/center]

Link to comment
Share on other sites

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

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 :idea:

Link to comment
Share on other sites

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 :mellow:

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...