Jump to content
Sign in to follow this  
Pyrex

Press a key to start the script?

Recommended Posts

Pyrex

With

While 1
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )
If IsArray($Coord) Then
MouseClick("left", $coord[0], $coord[1],2)
Else
MouseClick("left",,,2)
EndIf
WEnd

How can I get it to start if I press the 'spacebar'? Cause when I run it, it runs straight away and I don't want it to.

Share this post


Link to post
Share on other sites
Pain

look for HotKeySet in the helpfile

Share this post


Link to post
Share on other sites
monoceres

I actually think _IsPressed() is better in this situation, it doesn't make the code "better" but a lot more readable:

#include <misc.au3>
Do
    Sleep(50)
Until _IsPressed("20")

; Script continues here:
Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Pyrex

look for HotKeySet in the helpfile

Do I have a function in my code or do I need to set one?

That is what it says I need to put:

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

And how do I stop my script when I want it to stop?

#include <misc.au3>
Do
    Sleep(50)
Until _IsPressed("20")

; Script continues here:

What will ^^^ do?

Edited by Pyrex

Share this post


Link to post
Share on other sites
Pain

yes you need a function that should start when you press on the key.

to stop your script make HotKeySet("{ESC}", "Terminate")

with this function

Func Terminate()

Exit 0

EndFunc

Share this post


Link to post
Share on other sites
Pyrex

yes you need a function that should start when you press on the key.

to stop your script make HotKeySet("{ESC}", "Terminate")

with this function

Func Terminate()

Exit 0

EndFunc

Which function do I choose because it's got PixelSearch and MouseClick

Share this post


Link to post
Share on other sites
weaponx

Monoceres already posted the solution...it will get caught in a loop until the spacebar is hit, then the rest of the script will run. Come on people this is not rocket science.

Share this post


Link to post
Share on other sites
Pyrex

Monoceres already posted the solution...it will get caught in a loop until the spacebar is hit, then the rest of the script will run. Come on people this is not rocket science.

ok but where do i put it and what does it do?

Share this post


Link to post
Share on other sites
weaponx

ok but where do i put it and what does it do?

At the top! You said you didn't want anything to happen until after the keypress!

Share this post


Link to post
Share on other sites
Pyrex

i went into the game but nothing happens when i press spacebar

Share this post


Link to post
Share on other sites
newbiescripter

This what was monoceres said and it should work. I've put it in the loop for you and make continue until you press the spacebar again.. if you want it to be deactivated by another key, then look in the misc.au3 to see which ID the key has..

#include <misc.au3>
While 1
    Do
        Sleep(50)
    Until _IsPressed("20")
    
    Do  
        $coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )
        If IsArray($Coord) Then
            MouseClick("left", $coord[0], $coord[1],2)
        Else
            MouseClick("left","","",2)
        EndIf  
    Until _IsPressed("20")
WEnd

Regards

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  

×