Sign in to follow this  
Followers 0
jonasburger

New to Autoit, need help

9 posts in this topic

Hello folks,

As the title says, I am new to autoit. I am trying to set up a script that will check a certain pixel for a color. If it is a certain color it will press a specific key. It will then wait a few seconds and check again. I would also like to add a way to start the script and stop it. It seems like it should be pretty simple to do but I haven't written a script before so I don't know any of the commands. Any help anybody can provide would be appreciated.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I've never done anything like this, but straight from the help file....

$trigger=0
HotKeySet("{F9}","triggerDo")
Func triggerDo
If $trigger=0 Then
$trigger=1
Else
$trigger=0
EndIf
EndFunc

While $trigger=1
$var = PixelGetColor( x,y )
If $var=<deccolor> Then
;Where <deccolor> is the decimal value of the color you want. You can also cast Hex to make it a hex color.
Send("KEY")
WEnd

While 1

WENd

Assuming the pixel you wanted to get is at a fixed location, then input the location in x,y.

Otherwise use $pos = MouseGetPos(), and substitute x,y with $pos[0] and $pos[1].

Edited by CrewXp

Share this post


Link to post
Share on other sites

I've never done anything like this, but straight from the help file....

$trigger=0
HotKeySet("{F9}","triggerDo")
Func triggerDo
If $trigger=0 Then
$tigger=1
Else
$trigger=0
EndIf
EndFunc

While $trigger=1
$var = PixelGetColor( x,y )
If $var=<deccolor> Then
;Where <deccolor> is the decimal value of the color you want. You can also cast Hex to make it a hex color.
Send("KEY")
WEnd

Assuming the pixel you wanted to get is at a fixed location, then input the location in x,y.

Otherwise use $pos = MouseGetPos(), and substitute x,y with $pos[0] and $pos[1].

So how do I make it wait for few seconds after it does the key press and then automatically start checking again?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

For the While part of the code...

While $trigger=1
;Sleep(500)
$var = PixelGetColor( x,y )
If $var=<deccolor> Then
;Where <deccolor> is the decimal value of the color you want. You can also cast Hex to make it a hex color.
Send("KEY")
Sleep(1000)
;Above Code Waits Ten Seconds (in ms)
WEnd

Also, F9 Toggles the pixel checking On/Off. It starts with the script off, but if you press F9 once, it turns it on. If you press F9 again, it turns it off.

You might want to uncomment the ;Sleep(500) in the while so it only checks every half a second, to save system resources.

But for your question, the Sleep(1000) waits one seconds before looping to the top of the while statement again.

Edited by CrewXp

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

For the While part of the code...

While $trigger=1
;Sleep(500)
$var = PixelGetColor( x,y )
If $var=<deccolor> Then
;Where <deccolor> is the decimal value of the color you want. You can also cast Hex to make it a hex color.
Send("KEY")
Sleep(1000)
;Above Code Waits Ten Seconds (in ms)
WEnd

Also, F9 Toggles the pixel checking On/Off. It starts with the script off, but if you press F9 once, it turns it on. If you press F9 again, it turns it off.

You might want to uncomment the ;Sleep(500) in the while so it only checks every half a second, to save system resources.

But for your question, the Sleep(1000) waits one seconds before looping to the top of the while statement again.

OK, I did the script and compiled it. I am getting an error message in line 19 saying "Wend" statement with no matching "While"

I added an EndIf before the Wend and now I am getting an error saying badly formatted Func statement

Edited by jonasburger

Share this post


Link to post
Share on other sites

my bad. Add EndIf to the loop

While $trigger=1
;Sleep(500)
$var = PixelGetColor( x,y )
If $var=<deccolor> Then
;Where <deccolor> is the decimal value of the color you want. You can also cast Hex to make it a hex color.
Send("KEY")
Sleep(1000)
;Above Code Waits Ten Seconds (in ms)
EndIf
WEnd

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Here, this is better:

GLOBAL $trigger=0
HotKeySet("{F9}","triggerDo")

Func triggerDo()

If $trigger=0 Then
$trigger=1
Else
$trigger=0
EndIf
EndFunc


While 1
If $trigger=1 Then
Sleep(500)
$var = PixelGetColor( x,y )
If $var=<deccolor> Then
;Where <deccolor> is the decimal value of the color you want. You can also cast Hex to make it a hex color.
Send("KEY")
Sleep(1000)
;Above Code Waits One Second (in ms)
EndIf
;ToolTip($var,0,0)
EndIf
    WEnd
Edited by CrewXp

Share this post


Link to post
Share on other sites

did that work out?

Share this post


Link to post
Share on other sites

did that work out?

Seems to be working perfectly, thank you so much for the help

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