Jump to content

Script To Pause Between Keypresses


Recommended Posts

I am trying to write my first script, but am not sure how to start the script.

Within an application I am using, I would like a script to 'press' F1, wait 10 seconds, press F2, wait 10 seconds, press F3 then wait 45 seconds before starting again from F1. I'd like it to repeat 5 times.

I have written:

For $i = 5 to 1 Step -1

Send("{F1}")

sleep (10000)

Send("{F2}")

sleep (10000)

Send("{F3}")

sleep (45000)

Next

It seems to be working. However, my problem is in starting the script. If I double click the sceipt it starts running straight away. I can get around this by putting a sleep comand before the For...Next loop but I wanted to see if there was an easier way to start the script.

Edited by mte
Link to comment
Share on other sites

For $i = 5 to 1 Step -1

Send("{F1}")

sleep (10000)

Send("{F2}")

sleep (10000)

Send("{F3}")

sleep (45000)

Next

It seems to be working. However, my problem is in starting the script. If I double click the sceipt it starts running straight away. I can get around this by putting a sleep comand before the For...Next loop but I wanted to see if there was an easier way to start the script.

Welcome To The Forums!

just as a favor to other members, plz wrap your code in the code tags :)

Now, I would Write This Script like This

HotKetSet("{HOME}", "Init")
Global $on = 0

Func Init()
If $on = 0 Then
$on = 1
Else
$on = 0
EndIf
EndFunc

If $on = 1
While $i < 6
  Send("{F1}")
  sleep (10000)
  Send("{F2}")
  sleep (10000)
  Send("{F3}")
  sleep (45000)
  $i = $i + 1
Wend
EndIf

This Sends the buttons once you press the home key :(

Link to comment
Share on other sites

  • Moderators

Welcome To The Forums!

just as a favor to other members, plz wrap your code in the code tags :)

Now, I would Write This Script like This

HotKetSet("{HOME}", "Init")
Global $on = 0

Func Init()
If $on = 0 Then
$on = 1
Else
$on = 0
EndIf
EndFunc

If $on = 1
While $i < 6
  Send("{F1}")
  sleep (10000)
  Send("{F2}")
  sleep (10000)
  Send("{F3}")
  sleep (45000)
  $i = $i + 1
Wend
EndIf

This Sends the buttons once you press the home key :(

Paulie, you've got a bunch of errors there... also the If/Then statement will never happen because it isn't in a loop itself:
HotKeySet("{HOME}", "Init")
Global $on

While 1
    If $on = 1 Then
        For $i = 1 To 6
            ToolTip($on, 0, 0)
            Send("{F1}")
            Sleep (10000)
            Send("{F2}")
            Sleep (10000)
            Send("{F3}")
            Sleep (45000)
        Next
    EndIf
    Sleep(100)
    ToolTip($on, 0, 0)
WEnd

Func Init()
    $on = Not $on
EndFunc
You can take the ToolTip out if you want, It will just tell you where it's at.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Paulie, you've got a bunch of errors there... also the If/Then statement will never happen because it isn't in a loop itself:

HotKeySet("{HOME}", "Init")
Global $on

While 1
    If $on = 1 Then
        For $i = 1 To 6
            ToolTip($on, 0, 0)
            Send("{F1}")
            Sleep (10000)
            Send("{F2}")
            Sleep (10000)
            Send("{F3}")
            Sleep (45000)
        Next
    EndIf
    Sleep(100)
    ToolTip($on, 0, 0)
WEnd

Func Init()
    $on = Not $on
EndFunc
You can take the ToolTip out if you want, It will just tell you where it's at.
:) Your right Smoke i totally mist that. :">

sorry mte my bad,

Thank god smoke is here to fix all my mistakes :">

Link to comment
Share on other sites

  • Moderators

:) Your right Smoke i totally mist that. :">

sorry mte my bad,

Thank god smoke is here to fix all my mistakes :">

LMAO, I'd hardly call those "true" mistakes... those are, "I understand what you want", "I've done it before", "I'm typing in the Fast Reply Window and not SciTe", "Man I hope I don't make a mistake with Syntax" mistakes... lol.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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