Jump to content

Recommended Posts

Posted

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.

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
Posted

  CrewXp said:

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?
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
Posted (edited)

  CrewXp said:

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...