jonasburger Posted March 14, 2007 Posted March 14, 2007 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.
CrewXp Posted March 14, 2007 Posted March 14, 2007 (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 March 14, 2007 by CrewXp
jonasburger Posted March 14, 2007 Author Posted March 14, 2007 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?
CrewXp Posted March 14, 2007 Posted March 14, 2007 (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 March 14, 2007 by CrewXp
jonasburger Posted March 14, 2007 Author Posted March 14, 2007 (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 March 14, 2007 by jonasburger
CrewXp Posted March 14, 2007 Posted March 14, 2007 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
CrewXp Posted March 14, 2007 Posted March 14, 2007 (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 March 14, 2007 by CrewXp
jonasburger Posted March 14, 2007 Author Posted March 14, 2007 did that work out?Seems to be working perfectly, thank you so much for the help
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now