Here is my test scripts for checking to see if the ImageSearch/PixelSearch is actually on screen and then clicking it if found.
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
F1::
ImageSearch, foundX, foundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Users\ME\Desktop\AHK\example.bmp
If ErrorLevel = 0
{
MouseMove, %foundX%, %foundY%
Sleep, 66, 666
Click
}
If ErrorLevel = 1
{
MsgBox, O Damn - Cant find Image/Pixel
}
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;; OR ;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
F2::
PixelSearch, tX, tY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x111828, 3, Fast
If ErrorLevel = 0
{
MouseMove, %tX%, %tY%
Sleep, 66, 666
Click
}
If ErrorLevel = 1
{
MsgBox, O Damn - Cant find Image/Pixel
}
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
My problem is the fact that each and every time it find the image and clicks on it, it is clicking the EXACT SAME PIXEL every time, and as this is being used for an online game this is very much not ideal. Is there any way to click a Random spot WITHIN the image defined OR Click a random color defined pixel, instead of just finding image/color and clicking same pixel everytime? The idea would be that on the MouseMove to the location (whether it be PixelSearch or ImageSearch) it will then click at a random slightly off center position each time.
Now assuming that Question 1 has been solved, my next problem is as follows :-
Question 2:
Lets say on my screen i have 3 "rocks/images/pixelcolor" on screen, and when pressing F1:: due to the way it searches from top left to right then down it Is ALWAYS clicking the top left "rock/Image". How can i make it select from any one of the 3 found "rock/Images/pixelcolor" randomly?
Any help and ideas are welcome! Please let me know if my intentions are not clear and i will try to explain further,