Jump to content

Recommended Posts

Posted

Hi, I'm fairly new to AutoIt and I've been playing around with it, but I can't create the script that I want just yet.

All I want it to do is to press the x key on the keyboard every other second and have this run indefinitely until I close the program to end the script. Could anyone help me with this?

  • Moderators
Posted

Hi, I'm fairly new to AutoIt and I've been playing around with it, but I can't create the script that I want just yet.

All I want it to do is to press the x key on the keyboard every other second and have this run indefinitely until I close the program to end the script. Could anyone help me with this?

Look at While/WEnd - Sleep() - Send() in the helpfile.

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.

Posted (edited)

...until I close the program to end the script...

Welcome to the forums.

What SmOke_N said and...

while 1

if winexists... then

if winactive... then send x

else

exit

endif

sleep

wend

You can fill in the blanks using the help file and the AutoIt Window Info tool.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted

Here is what I have so far:

$i = 0

While 1 $i <= 100000

If WinExists("X Test") Then

If WinActive("X Test") Then

send (x)

$i = $i + 1

Wend

else

exit

endif

sleep

It keeps telling me that my Wend statement has no matching While statement, but I do have a While statement. I can't figure out why this won't work.

Posted

Oh thanks. I still don't understand why it says my Wend has no matching While if there's only one While and one Wend. Did I do something wrong with my While statement?

Posted (edited)

maybe

$i = 0
While 1 $i <= 100000
    If WinExists("X Test") Then
        If WinActive("X Test") Then
            Send(x)
            $i = $i + 1
        EndIf
    EndIf
    Sleep(10)
WEnd

the code tags help you see the visual "use" and location of each command...

also you should follow cybers suggestion

8)

Edited by Valuater

NEWHeader1.png

Posted (edited)

try

While 1
    If WinExists("X Test") Then
        If WinActive("X Test") Then Send("x")
    Else
        Exit
    EndIf
    Sleep(2000)
WEnd

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted (edited)

Ah thanks guys. One last question.

It says that x is an unknown function. I thought Send(x) was the way to send the x keystroke. I also tried Send("x") with no luck.

Edit: nevermind, got it working. Thanks all. =)

Edited by Snuggles

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
×
×
  • Create New...