Dariorio Posted June 13, 2016 Share Posted June 13, 2016 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 More sharing options...
Moderators JLogan3o13 Posted June 13, 2016 Moderators Share Posted June 13, 2016 @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 More sharing options...
Dariorio Posted June 13, 2016 Author Share Posted June 13, 2016 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 More sharing options...
Moderators JLogan3o13 Posted June 13, 2016 Moderators Share Posted June 13, 2016 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 More sharing options...
Dariorio Posted June 13, 2016 Author Share Posted June 13, 2016 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 More sharing options...
Dariorio Posted June 13, 2016 Author Share Posted June 13, 2016 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 More sharing options...
Moderators JLogan3o13 Posted June 13, 2016 Moderators Share Posted June 13, 2016 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 More sharing options...
Dariorio Posted June 13, 2016 Author Share Posted June 13, 2016 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 More sharing options...
Dariorio Posted June 14, 2016 Author Share Posted June 14, 2016 (edited) 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: expandcollapse popupHotKeySet("{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 June 14, 2016 by Melba23 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 14, 2016 Moderators Share Posted June 14, 2016 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. 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MuffinMan Posted June 14, 2016 Share Posted June 14, 2016 (edited) 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 June 14, 2016 by MuffinMan fixed extra 0x in hex color value Dariorio 1 Link to comment Share on other sites More sharing options...
Dariorio Posted June 14, 2016 Author Share Posted June 14, 2016 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 More sharing options...
MuffinMan Posted June 14, 2016 Share Posted June 14, 2016 Oops, sorry, I tried another color and left an extra "0x" in there when I put yours back. Remove that and try it again... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 14, 2016 Moderators Share Posted June 14, 2016 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Dariorio Posted June 14, 2016 Author Share Posted June 14, 2016 Ok so muffin, I tried it without the "0x" but it still doesn't work .. Link to comment Share on other sites More sharing options...
MuffinMan Posted June 14, 2016 Share Posted June 14, 2016 OK, so try this instead - it's the page I used to test with: Change your color to: Global $color1 = 0xFFFB00 Run the code and then point your browser up to this page: https://nurturingacreativeworld.files.wordpress.com/2014/12/195057182_640.jpg The middle yellow square is the target color. Dariorio 1 Link to comment Share on other sites More sharing options...
Dariorio Posted June 14, 2016 Author Share Posted June 14, 2016 Okay so that is very strange, it works perfectly with that site and that color. But not with the site I use.. Maybe it's a very strange color ?? That's my theory. Thanks so much for helping Link to comment Share on other sites More sharing options...
MuffinMan Posted June 14, 2016 Share Posted June 14, 2016 @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 More sharing options...
AutoBert Posted June 14, 2016 Share Posted June 14, 2016 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 More sharing options...
Dariorio Posted June 15, 2016 Author Share Posted June 15, 2016 AutoBert I know, I'm just experimenting. Yesterday was like day 2 I know AutoIt. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now