vierwald

Pixel search autoclick

9 posts in this topic

#1 ·  Posted

I am writing a script to click a button when it changes to a specific color.

$pixel = PixelSearch(0,0,714,432,0xFFFF00)
If IsArray($pixel) = True Then
    MouseClick ("primary", 714, 432, 1, 0)
EndIf

It works with this: https://www.mathsisfun.com/games/reaction-time.html

The problem is I need it to continuously scan the screen and click everytime the color changes i.e. to run forever.

What do I need to add to the script?

 

Share this post


Link to post
Share on other sites



#3 ·  Posted

I am a complete beginner so I have no clue how to implement a loop...

I am not trying automate anything. 

I am just trying to learn how to do this in case I need to use it in the future. 

Right now I'm just using this game as an example: https://www.mathsisfun.com/games/reaction-time.html

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

Well, it is pretty common that new members asking questions about PixelSearch in general have no real purpose for their question but in general are looking to automate a game. So please ensure you familiarize yourself with our forum rules before continuing asking questions.  

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted

Thank you for your input.

Did you look at the link? I said game for lack of a better word. If you actually open the webpage you can see it's actually a reaction time test thing... 

I fail to see why anyone would ever want to automate that...

Anyway, could anyone tell me if how to loop my script?

Share this post


Link to post
Share on other sites

#6 ·  Posted

Just now, vierwald said:

Did you look at the link? I said game for lack of a better word. If you actually open the webpage you can see it's actually a reaction time test thing... 

Yes ... and as you noticed: The thread is still open which is an indication. ;)

1 minute ago, vierwald said:

I fail to see why anyone would ever want to automate that...

Well... I can assure you many do not agree with you!

2 minutes ago, vierwald said:

Anyway, could anyone tell me if how to loop my script?

Thought I did give you a hint earlier, so did you open the helpfile and looked for it?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted

How about this one? Its in pdf, so u will be able to read it without any problems.

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

genord92,

Welcome to the AutoIt forums.

But what makes you think that posting a link to a Visual Basic tutorial will be helpful to someone who is programming in AutoIt?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

If you really interested in code, you must learn to research and try&error codes.

If you want to scan the screen all the time, you must use a loop. If you do not know how, just google "while loop autoit" --> https://www.autoitscript.com/autoit3/docs/keywords/While.htm

so...

$color = ;put your color here
while (true)
sleep(10)
    $colorPos = PixelSearch(0, 0, 714, 432, $color)
    If Not @error Then
        MouseClick("left",$colorPos[0],$colorPos[1])
    EndIf
WEnd

i did not tested the code, but it should be correct, however, if its not you can fix it.

Share this post


Link to post
Share on other sites

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