7upinhere Posted July 20, 2014 Share Posted July 20, 2014 Hi I am currently trying to speed up the following code expandcollapse popup; Press Esc to terminate script, Pause/Break to "pause" Global $Paused, $counter = 0 HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d ;;;; Body of program would go here;;;; While 1 $coord = PixelSearch( 1490, 720, 1776, 720, 0x202020, 0 ) If @error = 0 Then ;; if color found the do action MouseMove($coord[0],$coord[1]) mouseclick("left") Sleep(15) Else ;; if not wait 5 secs and repeat Sleep(1000) EndIf Wend ;;;;;;;; Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) ToolTip('Script is "Paused"',0,0, $counter, 1) WEnd ToolTip("") EndFunc Func Terminate() Exit 0 EndFunc Func ShowMessage() MsgBox(4096,"","This is a message.") EndFunc the above "works" but I think that searching 4 specific pixels for 0x202020 rather than a range of pixels would be much faster? So I used Autoit window info to gather the following information pixel1 1400, 530 0x202020 pixel2 1560, 530 0x202020 pixel3 1700, 530 0x202020 pixel4 1850, 530 0x202020 now with my basic knowledge I understand that using if/else I would need to set the pixelsearch to for the first location which seeing the correct pixel colour would click the mouse While 1 $coord = PixelSearch( 1400, 530, 1400, 530, 0x202020, 0 ) If @error = 0 Then ;; if color found the do action MouseMove($coord[0],$coord[1]) mouseclick("left") Sleep(15) Else ;; if not wait 5 secs and repeat Sleep(1000) EndIf Wend and if 0x202020 was not present at 1400, 530 it would then check 1560, 530 and if not present there it would check 1700, 530 and so on. looped so I am guessing that that information would go in the else section but I am having trouble converting my thinking into correct code Any help would be much appreciated. Link to comment Share on other sites More sharing options...
7upinhere Posted July 20, 2014 Author Share Posted July 20, 2014 Or would it perhaps go after the first $coord = PixelSearch( 1490, 720, 1776, 720, 0x202020, 0 ) Something like this $coord = PixelSearch( 1400, 720, 1400, 720, 0x202020, 0 ), $coord2 = PixelSearch( 1560, 720, 1560, 720, 0x202020, 0 ), $coord3 = PixelSearch( 1700, 720, 1700, 720, 0x202020, 0 ), $coord4 = PixelSearch( 1850, 720, 1850, 720, 0x202020, 0 ) Or am I way off track? Thanks. Link to comment Share on other sites More sharing options...
JohnOne Posted July 20, 2014 Share Posted July 20, 2014 PixelGetColor AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
7upinhere Posted July 20, 2014 Author Share Posted July 20, 2014 (edited) Ok so I assume you are saying that PixelGetColour is a faster method than pixelsearch This is what I just came up with im sure I have the grammar of AHK wrong could I get some feedback on it thank you HotKeySet("{ESC}", "Terminate") $box1 = PixelGetColor(1400, 530) $box2 = PixelGetColor(1560, 530) $box3 = PixelGetColor(1700, 530) $box4 = PixelGetColor(1850, 530) if $box1 = 0x202020 Then MouseMove($box1[0],$box1[1]) mouseclick("left") Sleep(15) Else if $box2 = 0x202020 Then MouseMove($box2[0],$box2[1]) mouseclick("left") Sleep(15) Else if $box3 = 0x202020 Then MouseMove($box3[0],$box3[1]) mouseclick("left") Sleep(15) Else if $box4 = 0x202020 Then MouseMove($box4[0],$box4[1]) mouseclick("left") Sleep(15) Edited July 20, 2014 by 7upinhere Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 20, 2014 Moderators Share Posted July 20, 2014 7upinhere, I have the grammar of AHK wrongThe language you are using is AutoIt. 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...
Developers Jos Posted July 20, 2014 Developers Share Posted July 20, 2014 im sure I have the grammar of AHK wrong could I get some feedback on it thank you AHK ? What about you try a little more research yourself by opening the helpfile and checking out the proper syntax? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
7upinhere Posted July 20, 2014 Author Share Posted July 20, 2014 (edited) Sorry mybad I was in a rush to leave and got the two confused. Ok I have given it another go and tried to tidy it up still with not much luck, I checked over the help file about the correct grammar and I think I did it correct. HotKeySet("{ESC}", "Terminate") HotKeySet("{c}", "Copy") Local $box1 = PixelGetColor(1400, 530) Local $box2 = PixelGetColor(1560, 530) Local $box3 = PixelGetColor(1700, 530) Local $box4 = PixelGetColor(1850, 530) local $colour = 0x202020 if $box1 = $colour Then MouseMove($box1[0],$box1[1]) mouseclick("left") Sleep(15) ElseIf $box2 = $colour Then MouseMove($box2[0],$box2[1]) mouseclick("left") Sleep(15) ElseIf $box3 = $colour Then MouseMove($box3[0],$box3[1]) mouseclick("left") Sleep(15) Elseif $box4 = $colour Then MouseMove($box4[0],$box4[1]) mouseclick("left") Sleep(15) EndIf Edited July 20, 2014 by 7upinhere Link to comment Share on other sites More sharing options...
Bert Posted July 20, 2014 Share Posted July 20, 2014 I notice you use LOTS of mouseclicks. Is there some reason you can't use ControlClick? Much more stable and if the window loses focus the control will still be clicked. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
7upinhere Posted July 20, 2014 Author Share Posted July 20, 2014 I notice you use LOTS of mouseclicks. Is there some reason you can't use ControlClick? Much more stable and if the window loses focus the control will still be clicked. I guess there is no reason not to use ControlClick I just saw examples of MouseClick and thought that would be best to use. The application that the script will be interfacing will be running on a separate laptop so there is no need to worry about it not being on top. Anyway I would like to figure out why its not working before I rewrite it using contolclicks but thank you for the advice. Link to comment Share on other sites More sharing options...
Shane0000 Posted July 20, 2014 Share Posted July 20, 2014 (edited) PixelGetColor returns the color at co-ordinates x,y In your updated example @ #7 ; $Box1 is not an array, it is a color Try something like below Edit - Made recursive Ifs , I think this will speed up your program, if color is found at the first opixel this will skip the rest of the searches HotKeySet("{ESC}", "Terminate") HotKeySet("{c}", "Copy") Local $Box1[2] = [1400,530] Local $Box2[2] = [1560,530] Local $Box3[2] = [1700,530] Local $Box4[2] = [1850,530] Local $Color1 = PixelGetColor($box1[0], $box1[1]) local $colour = 0x202020 If $Color1 = $colour Then MouseMove($box1[0],$box1[1]) mouseclick("left") Sleep(15) Else If $colour = PixelGetColor($box2[0], $box2[1]) Then MouseMove($box2[0],$box2[1]) mouseclick("left") Sleep(15) Else If $colour = PixelGetColor($box3[0], $box3[1]) Then MouseMove($box3[0],$box3[1]) mouseclick("left") Sleep(15) Else If $colour = PixelGetColor($box4[0], $box4[1]) Then MouseMove($box4[0],$box4[1]) mouseclick("left") Sleep(15) Else MsgBox(0,'Error','No Matches Found.') EndIf EndIf EndIf EndIf Edited July 20, 2014 by Shane0000 Link to comment Share on other sites More sharing options...
Bert Posted July 21, 2014 Share Posted July 21, 2014 Second question: Is there a reason why you have to use PixelGetColor? When I write scripts I try to avoid that method at all cost. It is the most unstable method to detect change. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
7upinhere Posted July 21, 2014 Author Share Posted July 21, 2014 Second question: Is there a reason why you have to use PixelGetColor? When I write scripts I try to avoid that method at all cost. It is the most unstable method to detect change. PixelGetColor PixelGetColor returns the color at co-ordinates x,y In your updated example @ #7 ; $Box1 is not an array, it is a color Try something like below Edit - Made recursive Ifs , I think this will speed up your program, if color is found at the first opixel this will skip the rest of the searches HotKeySet("{ESC}", "Terminate") HotKeySet("{c}", "Copy") Local $Box1[2] = [1400,530] Local $Box2[2] = [1560,530] Local $Box3[2] = [1700,530] Local $Box4[2] = [1850,530] Local $Color1 = PixelGetColor($box1[0], $box1[1]) local $colour = 0x202020 If $Color1 = $colour Then MouseMove($box1[0],$box1[1]) mouseclick("left") Sleep(15) Else If $colour = PixelGetColor($box2[0], $box2[1]) Then MouseMove($box2[0],$box2[1]) mouseclick("left") Sleep(15) Else If $colour = PixelGetColor($box3[0], $box3[1]) Then MouseMove($box3[0],$box3[1]) mouseclick("left") Sleep(15) Else If $colour = PixelGetColor($box4[0], $box4[1]) Then MouseMove($box4[0],$box4[1]) mouseclick("left") Sleep(15) Else MsgBox(0,'Error','No Matches Found.') EndIf EndIf EndIf EndIf Yep this works great thanks I added a while/wend to make it loop and made a few minor adjustments. Link to comment Share on other sites More sharing options...
Bert Posted July 22, 2014 Share Posted July 22, 2014 you never did answer the question I asked. Why do you HAVE to use PixelGetColor? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
7upinhere Posted July 22, 2014 Author Share Posted July 22, 2014 you never did answer the question I asked. Why do you HAVE to use PixelGetColor? I did not HAVE to use PixelGetColour it was suggested by John who by judging from his/her post count has a good enough knowledge of autoit. It would be a bit dumb me coming here for advice and then not trying advice that was offered, no? Link to comment Share on other sites More sharing options...
JohnOne Posted July 22, 2014 Share Posted July 22, 2014 PixelGetColor is more appropriate than PixelSearch in this instance here. MBALZESHARI is hinting there may be better ways than Pixel functions all together depending on what you are working with. For example if you were working with a standard native windows GUI there would almost certainly be a more stable way. Bert 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Bert Posted July 22, 2014 Share Posted July 22, 2014 PixelGetColor is more appropriate than PixelSearch in this instance here. MBALZESHARI is hinting there may be better ways than Pixel functions all together depending on what you are working with. For example if you were working with a standard native windows GUI there would almost certainly be a more stable way. That is what I'm getting at. Thanks John! The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Werty Posted July 22, 2014 Share Posted July 22, 2014 Try changing your desktop theme to "Classical", that often speeds up pixelgetcolor, read this thread about it... '?do=embed' frameborder='0' data-embedContent>> Some guy's script + some other guy's script = my script! 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