MouseMove, Color Clicker

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GA-Fantonos
Posts: 4
Joined: 17 Sep 2018, 22:57

MouseMove, Color Clicker

20 Sep 2018, 17:05

i just started about a week ago coding so please don't make fun of me, ok just a little .
here is a script someone helped me make so far all it does is just send "r" if the left mouse button hasn't been click in 10 secs
but i also need it to click on the colors 0xA77336 ,0x135EE2 ,0x03D9F3 as soon as it appears on my screen
and i could start the whole script by pressing ctrl+[key1] always running unless i press Ctrl+[key2]
here is what i did but only the sending "r" if the mouse hasn't been clicked works while the color clicker doesn't
is there a better way to click these colors
or is there a better way to make this script?
any help would be appreciated.

Code: Select all

z:: ; the trigger can be anything i put [z] as a example
PixelSearch, Px, Py, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0xA77336, 0x135EE2, 0x03D9F3, 0, Fast ; 0xA77336, 0x135EE2, 0x03D9F3 are the 3 colors i want it to look for
if ErrorLevel
    Send, z ;the way i did it here it has to be the same as the trigger[z] so it can loop, only if the colors arent found
else
   click %Px%, %Py% ;even if the colors is found it needs to do the "else" then run the trigger[z] once more once more
   Sleep, 10
   click %Px%, %Py%
   Sleep 10
   send, z
return
;mouse click wait ten seconds then send "r"
#Persistent
MouseGetPos, Xold, Yold
MoveTime := A_TickCount + 10000
SetTimer, Mouse, 100
Return
Mouse:
MouseGetPos, X, Y
If (X <> Xold Or Y <> Yold)
{
	MoveTime := A_TickCount + 10000
	Xold := X, Yold := Y
}
If (MoveTime < A_TickCount)
{
	SendInput, r
	MoveTime := A_TickCount + 10000
}
Return

e:: ;exit app it can be anything i put e as a example
 ExitApp
return

#SingleInstance,force
buttshark
Posts: 62
Joined: 22 Apr 2017, 20:57

Re: MouseMove, Color Clicker

22 Sep 2018, 04:26

I am not in a position to test my solution, but this should work. The reason why your pixel search isn't working is because you messed up the parameters; you are only allowed ONE color to look for. Therefore, you must do 3 searches. Secondly, although recursion is pretty sweet, I would just use a loop to keep checking for the colors

Code: Select all

while(!Px1 AND ! Px2 AND !Px3)
{
	PixelSearch, Px1, Py1, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0xA77336, 0, Fast
	PixelSearch, Px2, Py2, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x135EE2, 0, Fast
	PixelSearch, Px3, Py3, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x03D9F3, 0, Fast
}
;when this exits the loop, one of the 3 colors will have been found
Sidenote: I'm not sure if you are aware, but PixelSearch's color is formatted as BGR, not the standard RGB. If your colors are in RGB form, you can add 'RGB' next to 'Fast' to fix it.

Second, you say you want to send 'r' if you haven't clicked, but your example is for if the cursor moves or not. I'm going to assume you want to send 'r' every 10 seconds if you haven't moved the mouse. I again can't check to see if this works, but your setup for checking if the mouse moves every 10 seconds is pretty jenky. I would just use a SetTimer every 10 seconds and check for a difference.

Code: Select all

MouseGetPos, Xold, Yold
SetTimer, Mouse, 10000
Return

Mouse:
MouseGetPos, X, Y
if(X != Xold AND Y != Yold)
	SendInput, r
Xold := X
Yold := Y
Return
Put them together and add a way to exit the script, you should be golden.

Code: Select all

^z:: ;ctrl+z start
MouseGetPos, Xold, Yoldr
SetTimer, Mouse, 1000
while(!Px1 AND !Px2 AND !Px3)
{
	PixelSearch, Px1, Py1, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0xA77336, 0, Fast
	PixelSearch, Px2, Py2, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x135EE2, 0, Fast
	PixelSearch, Px3, Py3, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x03D9F3, 0, Fast
}
Px := Px1 ? Px1 : (Px2 ? Px2 : Px3) ;set Px to the one found
Py := Py1 ? Py1 : (Py2 ? Py2 : Py3) ;set Py to the one found
Click, %Px%, %Py%
return

Mouse:
MouseGetPos, X, Y
if(X != Xold AND Y != Yold)
	SendInput, r
Xold := X
Yold := Y
Return

^e::ExitApp ;ctrl+e exit
I have no idea what I'm doing.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, mikeyww and 460 guests