Jump to content

Need help with with basic script (new to autoIt)


Recommended Posts

First off, Hello everyone I'm new to AutoIt and the forums here. 

So.. I want to automatically click if the color of the pixel is equal to $color1

But I just can't get it to work so anyone who could give me a solution with explanation would be perfect!

Here is my code and thanks in advance!

 

HotKeySet("{F4}", "MyExit")

$pos = MouseGetPos()
Global $color1 = 0xDEDEDE
Global $color2 = PixelGetColor

While(1)


$posx = random(4,1915)
$posy = random(184,1014)

    MouseMove( $posx, $posy)
    sleep(1000)

    PixelGetColor($pos[0], $pos[1])

    if $color1 == $color2 Then


    MouseClick("Left")

    sleep(200)

    Else

    sleep(100)

    EndIf


    WEnd

func MyExit()
    Exit
    EndFunc

 

 

 

Link to comment
Share on other sites

  • Moderators

@Dariorio it is a little difficult to troubleshoot if we can't see what you're trying to click on. Are you getting an error of some sort, or does AutoIt just not find the color? What are you trying to accomplish with the mouseclick? Is it something you can use ControlClick for (generally much much easier)?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Just now, JLogan3o13 said:

@Dariorio it is a little difficult to troubleshoot if we can't see what you're trying to click on. Are you getting an error of some sort, or does AutoIt just not find the color? What are you trying to accomplish with the mouseclick? Is it something you can use ControlClick for (generally much much easier)?

Alright yeah my bad. I'm trying to randomise my mouse movement and when it hits a certain color I want it to click. I don't get any errors what so ever, but when my mouse jumps on the color (As it should) the script doesn't click.. And I can't figure out why excactly. I'm trying to click on a regular checkmark  button by the way. Thanks for the fast reply also! I hope this is enough information

Link to comment
Share on other sites

  • Moderators
41 minutes ago, Dariorio said:

 I hope this is enough information

I guess I am not understanding what you're after, if you're trying to click a "checkmark button" why do you want to "randomise" it? Is this a GUI application (if so, which?) or is it in a webpage (URL would be helpful)?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

5 minutes ago, JLogan3o13 said:

I guess I am not understanding what you're after, if you're trying to click a "checkmark button" why do you want to "randomise" it? Is this a GUI application (if so, which?) or is it in a webpage (URL would be helpful)?

Well It's not really important what I want to click on because I'm just experimenting with AutoIt since I'm new to the program. The point is that I can't figure out how to automatically click on a color when the mouse hovers over it. Really hope someone could help me.

Link to comment
Share on other sites

1 minute ago, Dariorio said:

Well It's not really important what I want to click on because I'm just experimenting with AutoIt since I'm new to the program. The point is that I can't figure out how to automatically click on a color when the mouse hovers over it. Really hope someone could help me.

Also, the URL is: http://mrdoob.com/#/106/checkbox_painter

 

(Was not sure if I'm allowed to put links in)

Link to comment
Share on other sites

  • Moderators
17 minutes ago, Dariorio said:

Well It's not really important what I want to click on because I'm just experimenting with AutoIt since I'm new to the program. The point is that I can't figure out how to automatically click on a color when the mouse hovers over it. Really hope someone could help me.

It is really important, as otherwise you are asking us to first guess at what you're trying to do and then troubleshoot for you. The more information you provide, the more likely you will be to get the assistance you're after. Not everyone is going to spend the time to pull teeth in order to get basic info so they can help ;)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Just now, JLogan3o13 said:

It is really important, as otherwise you are asking us to first guess at what you're trying to do and then troubleshoot for you. The more information you provide, the more likely you will be to get the assistance you're after. Not everyone is going to spend the time to pull teeth in order to get basic info so they can help ;)

 

Yea true, do you have enough information to help, I have no other information..

 

Link to comment
Share on other sites

Okay so, I have an other topic running but wasn't providing enough information so I hope if I start this topic with all the information provided that I will get help. So I have no "GOAL". I'm just experimenting with AutoIt. But I got stuck, I wanted to move the mouse every 1 second to a different spot in a specified area on the screen and if the mouse moved to a specific color it would click. But the problem now is, it isn't working and I dont know why. I use this site for testing my script: http://mrdoob.com/#/106/checkbox_painter . So.. When my mouse jumps on a checkmark it should click but it doesn't and I hope you guys can help me! Thanks in advance. This is the script I got for now: 

HotKeySet("{F4}", "MyExit")


$pos = MouseGetPos()
Global $color1 = 0xDEDEDE
Global $color2 = PixelGetColor

While(1)


$posx = random(4,1915)
$posy = random(184,1014)

    MouseMove( $posx, $posy)
    sleep(1000)

    PixelGetColor($pos[0], $pos[1])

    if $color1 == $color2 Then


    MouseClick("Left")

    sleep(200)

    Else

    sleep(100)

    EndIf


    WEnd

func MyExit()
    Exit
EndFunc

 

Edited by Melba23
Link to comment
Share on other sites

  • Moderators

Dariorio,

Quote

so, I have an other topic running

So please stick with it.

M23

P.S. When you post code please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I wasn't able to visit your website due to our web filters at work, but I did notice a couple of issues with your code.  Try the changes below and see if it works better for you:

HotKeySet("{F4}", "MyExit")


$pos = MouseGetPos()
Global $color1 = 0xDEDEDE
Global $color2 = PixelGetColor ; Not correct syntax and color needs to be grabbed after each mouse movment

While(1)

    $posx = random(4,1915)
    $posy = random(184,1014)

    MouseMove( $posx, $posy)
    sleep(1000)

    $pos = MouseGetPos() ; You weren't updating your mouse pos after the mouse was moved
    $color2 = PixelGetColor($pos[0], $pos[1]) 

    If $color1 == $color2 Then ; You weren't valuing $color2 properly before the While
        Msgbox(0,"Got it", "Thats my color") ; added to help troublehsoot

        MouseClick("Left")

        sleep(200)

    Else

        sleep(100)

    EndIf

WEnd

func MyExit()
    Exit
EndFunc

 

Edited by MuffinMan
fixed extra 0x in hex color value
Link to comment
Share on other sites

6 minutes ago, MuffinMan said:

I wasn't able to visit your website due to our web filters at work, but I did notice a couple of issues with your code.  Try the changes below and see if it works better for you:

HotKeySet("{F4}", "MyExit")


$pos = MouseGetPos()
Global $color1 = 0x0xDEDEDE
Global $color2 = PixelGetColor ; Not correct syntax and color needs to be grabbed after each mouse movment

While(1)

    $posx = random(4,1915)
    $posy = random(184,1014)

    MouseMove( $posx, $posy)
    sleep(1000)

    $pos = MouseGetPos() ; You weren't updating your mouse pos after the mouse was moved
    $color2 = PixelGetColor($pos[0], $pos[1]) 

    If $color1 == $color2 Then ; You weren't valuing $color2 properly before the While
        Msgbox(0,"Got it", "Thats my color") ; added to help troublehsoot

        MouseClick("Left")

        sleep(200)

    Else

        sleep(100)

    EndIf

WEnd

func MyExit()
    Exit
EndFunc

 

First, I want to thank you, there is only one little problem left. You put the "0x" in front of the color so the program recognises it as a color. Now when I try and run the script it gives an error: "error: syntax error". Just don't know how to fix that so yea :$

Link to comment
Share on other sites

  • Moderators

Dariorio,

Just remove the first "0x" so that it reads as before.

And when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

@Dariorio , sometimes the colors in images can fluctuate a lot, but we really can't tell the difference.  The PixelSearch function will search a range and see if some variation of that color is there.  I have not used it before, but had a little time to kill while I sat on a conference call.  Try the code below on your original test page and see what happens.  If you still have issues, try bumping the last parameter of the pixelsearch up a little and try again.  The help file will tell you more about how the shade variation works in PixelSearch.

 

HotKeySet("{F4}", "MyExit")

$pos = MouseGetPos()
Global $color1 = "0xDEDEDE"

While(1)

    $posx = random(4,1915)
    $posy = random(184,1014)

    MouseMove($posx, $posy)
    sleep(1000)

    $pos = MouseGetPos()
    $color2 = PixelGetColor($pos[0], $pos[1])

    $PixRange = PixelSearch($pos[0],$pos[1],$pos[0],$pos[1], $color1, 5) ; 5 is the shade variation setting (can be 0-255)
    If IsArray($PixRange) Then ;If pixel color is within the range of variable $color1, an array will be created
        Msgbox(0,"Got it", "Thats very close to my color") ; added to help test/troublehsoot
        MouseClick("left")
        Sleep(200)

    Else

        Sleep(100)

    EndIf

WEnd

func MyExit()
    Exit
EndFunc

 

Link to comment
Share on other sites

4 hours ago, MuffinMan said:

I wasn't able to visit your website due to our web filters at work, but I did notice a couple of issues with your code.

I visisit it, but this script with a websit like a 'Online Paint' with this script seemce noncence.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...