Detecting a certain color, move the mouse color and click it. How do I do that?

Ask gaming related questions (AHK v1.1 and older)
Roxysaurus
Posts: 1
Joined: 12 Apr 2018, 09:22

Detecting a certain color, move the mouse color and click it. How do I do that?

Post by Roxysaurus » 12 Apr 2018, 10:01

I have no idea how to do this. I've tried a few things, after trying to learn the basics but things didn't turn out so well. Actually, nothing ended up working.
I'm not good at this.

Basically I'm trying to make a code for collecting coins in game.
I want to detect a certain color, move the mouse to this specific color and right-click it.
This way it should click all the coins on the screen.

When the color/coin is not in the sceen, the left or right arrow-key should be pressed for 3 - 5 seconds (this will change the camera, in game.)
And then it should check again for the color.

That's all.
I hope someone's willing to make the code for me. It'll help me out alot.

greetings from the Netherlands

User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Detecting a certain color, move the mouse color and click it. How do I do that?

Post by Nwb » 12 Apr 2018, 12:19

Hey buddy!

I'll set you up, and if you do exactly as instructed it should work. But tell me if it doesn't or there's something you want to change or add to the script itself.

Firstly:

Code: Select all

F1::
KeyWait, LButton, down
MouseGetPos, CurrentX, CurrentY
PixelGetColor, Color, %CurrentX%, %CurrentY%
Gui, add, edit, h100 , select this: %Color%
Gui, Show
return

GuiClose:
Gui, Destroy
return 
Run this code ^. Open your game and go near coins. Now click F1 (once), and click one of the coins (be very careful). You will see a text select whatever is after "select this:"

Perfect. Now we have the color needed to search for.

Main script:

Code: Select all

#MaxThreadsPerHotkey 2
F2:: ; Change this to any hotkey you prefer
Toggle := !Toggle
Loop {
PixelSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, ****, , Fast
If ErrorLevel {
Send {Left down} ; change "left to right if you want it to hold right
Sleep 3000 ; edit this to how long you want to hold the button
Send {Left up} ; change "left to right if you want it to release right
}
else {
MouseMove, %X%, %y%
Click, Right 
}
Sleep 100 ; Less sleep = do more often. More sleep = do less often. edit this to any value you prefer
If not Toggle 
	break
}
return

^esc:: ExitApp ; Change this to any hotkey you prefer
^^ This is everything you asked for. Replace the "****" with what you had selected and you're script is ready.

Notes:
1) press F2 to start/stop script.
2) press Ctrl+Esc to close script.
3) If you want minor adjustments refer the comments.

Good luck!
I am your average ahk newbie. Just.. a tat more cute. ;)

loredana56
Posts: 7
Joined: 18 Jan 2022, 20:56

Re: Detecting a certain color, move the mouse color and click it. How do I do that?

Post by loredana56 » 20 Jan 2022, 20:01

Nice evening but I use a shotgun with a chamber without the arrow as I can do

Post Reply

Return to “Gaming Help (v1)”