Sign in to follow this  
Followers 0
ponchato

A simple two-key macro... I think.

6 posts in this topic

#1 ·  Posted (edited)

I'm pretty new to scripting, especially with Autoit. The point of this script (other than to get experience and because writing scripts is actually kind of fun) is to send tab, then send down (repeatedly) until I press a key on the keyboard. I've made... little progress, to say the least.

HotKeySet("{PAUSE}", "Paused")

Do
    Send("{TAB}")
    Send("{DOWN}")
Until Func Paused

Func Paused()
    While Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
EndFunc

As you can see, I'm missing some stuff. Now, the questions.

1) How do I make it perform a 'do...until' loop until the 'Paused' function is... uh, complete? That is, how do I make it loop until I press the 'Pause' key?

2) Can 'until' use a function to stop the loop in the first place? If not, I'm going at this whole script incorrectly.

3) Can I run the script, pause it, go to the window I need it run in, then start it again?

4) Instead of looping until I tell it to stop, is there a way to have it loop, say, 30 times then stop?

Sorry if I made mistakes that make you cringe because of their simplicity. I'm new to scripting, so cut me some slack.

Edited by ponchato

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm pretty new to scripting, especially with Autoit. The point of this script (other than to get experience and because writing scripts is actually kind of fun) is to send tab, then send down (repeatedly) until I press a key on the keyboard. I've made... little progress, to say the least.

HotKeySet("{PAUSE}", "Paused")

Do
    Send("{TAB}")
    Send("{DOWN}")
Until Func Paused

Func Paused()
    While Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
EndFunc

As you can see, I'm missing some stuff. Now, the questions.

1) How do I make it perform a 'do...until' loop until the 'Paused' function is... uh, complete? That is, how do I make it loop until I press the 'Pause' key?

2) Can 'until' use a function to stop the loop in the first place? If not, I'm going at this whole script incorrectly.

3) Can I run the script, pause it, go to the window I need it run in, then start it again?

4) Instead of looping until I tell it to stop, is there a way to have it loop, say, 30 times then stop?

Sorry if I made mistakes that make you cringe because of their simplicity. I'm new to scripting, so cut me some slack.

I have no idea what that Do Until stuff is about, but here is how I would do it:

HotKeySet("{SPACE}", "Pause")
HotKeySet("{ENTER}", "Resume")

Func Pause()
 $run = false
EndFunc

Func Resume()
 $run = true
EndFunc

$run = true

While 1
If $run = true Then
Send("{TAB}")
Send("{DOWN}")
EndIf
WEnd
Edited by aggixx

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Until Func Paused
While Paused

Uh these two logic checks don't make any sense :)

In the first case, even though "Func Paused" doesn't make sense as a logic check, once the "Until" 's check is satisfied it will start executing stuff after the do until loop, which in this case is nothing and the program will terminate.

In the While Paused, in addition to "Paused" not being a valid expression, there's nothing that would allow the expression to be false and thus exit the loop.

4) Instead of looping until I tell it to stop, is there a way to have it loop, say, 30 times then stop?

For-next loop. It's it's most basic form:

For $i = 1 to 30
Send("{TAB}")
Send("{DOWN}")
Next

I would make one small modification to aggixx's code:

HotKeySet("{SPACE}", "Pause")
HotKeySet("{ENTER}", "Resume")

Func Pause()
 $run = false
EndFunc

Func Resume()
 $run = true
EndFunc

$run = true

While 1
If $run = true Then
Send("{TAB}")
Send("{DOWN}")
Else
sleep(10)
EndIf
WEnd

I added a sleep in the "else" case to keep the script from chewing up CPU time.

Edited by TurionAltec

Share this post


Link to post
Share on other sites

Your guys' pause stuff is weird. Try this for you script:

Global $Paused
HotKeySet("{PAUSE}", "Pause")

While 1
    Send("{TAB}")
    Send("{DOWN}")
WEnd

Func Pause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip("Script is paused.")
    WEnd
EndFunc

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

Woah, thanks everyone. :)

While $Paused
        Sleep(100)
        ToolTip("Script is paused.")
    WEnd
Just to clarify, the Sleep(100) means that, when it's paused, it stays off for a tenth of a second, runs through to the beginning of 'While' and repeats the 100 millisecond sleep until the script is started again, right?

It's hard to describe a script in plain English.

Share this post


Link to post
Share on other sites

yes. The sleep(100) will just allow a little down time to keep the script from consuming the CPU.

Share this post


Link to post
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
Sign in to follow this  
Followers 0