JJ1122 Posted October 21, 2020 Share Posted October 21, 2020 (edited) expandcollapse popup#include <Misc.au3> #include <FastFind.au3> #include <WinAPI.au3> #include <APIConstants.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> $color = 16765255 ; 색깔# $colorhex = 0xffd247 $coord1 = 763 $coord2 = 841 $coord3 = 919 $coord4 = 997 $count = 0 While 1 If $count = 0 Then $mouse = MouseGetPos() EndIf $button4 = PixelGetColor($coord4, 606) If $button4 = $color Then MouseClick("left", $coord4 + 30, 625, 1, 1) $count += 1 EndIf $button4 = PixelGetColor($coord4, 606) $button3 = PixelGetColor($coord3, 606) If $button4 <> $color And $button3 = $color Then MouseClick("left", $coord3 + 30, 625, 1, 1) $count += 1 EndIf $button4 = PixelGetColor($coord4, 606) $button3 = PixelGetColor($coord3, 606) $button2 = PixelGetColor($coord2, 606) If $button4 <> $color And $button3 <> $color And $button2 = $color Then MouseClick("left", $coord2 + 30, 625, 1, 1) $count += 1 EndIf $button4 = PixelGetColor($coord4, 606) $button3 = PixelGetColor($coord3, 606) $button2 = PixelGetColor($coord2, 606) $button1 = PixelGetColor($coord1, 606) If $button4 <> $color And $button3 <> $color And $button2 <> $color And $button1 = $color Then MouseClick("left", $coord1 + 30, 625, 1, 1) $count += 1 EndIf WEnd There are four buttons that light up in certain conditions, and I am trying to click them as fast as I can. Also, I MUST press Button 4 before Button 3, 3 before 2, and 2 before 1. Which is the reason I wrote it like: $button4 = PixelGetColor($coord4, 606) $button3 = PixelGetColor($coord3, 606) $button2 = PixelGetColor($coord2, 606) $button1 = PixelGetColor($coord1, 606) If $button4 <> $color And $button3 <> $color And $button2 <> $color And $button1 = $color Then... I am currently using PixelGetColor, but I'm not sure if this is the best way to do this process loop. Is there any faster function which does the same thing as PixelGetColor? Or possibly any way to accelerate the process..? + If anyone can help compress the coding neatly, It'll be great, too. Edited October 21, 2020 by JJ1122 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 21, 2020 Share Posted October 21, 2020 @JJ1122 Pixel* functions are usually not the best solution for automate tasks. Which process are you trying to automate? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
JockoDundee Posted October 21, 2020 Share Posted October 21, 2020 3 hours ago, JJ1122 said: There are four buttons that light up in certain conditions, and I am trying to click them as fast as I can. It sounds as though you are doing something with an Excel spreadsheet. Amiright? Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
JJ1122 Posted October 21, 2020 Author Share Posted October 21, 2020 8 hours ago, FrancescoDiMuro said: @JJ1122 Pixel* functions are usually not the best solution for automate tasks. Which process are you trying to automate? It's an electric circuit management program made by one of my friends. Link to comment Share on other sites More sharing options...
Nine Posted October 21, 2020 Share Posted October 21, 2020 Remove useless call to PixelGetColor : expandcollapse popup$color = 16765255 $colorhex = "0x" & Hex($color) $coord1 = 763 $coord2 = 841 $coord3 = 919 $coord4 = 997 $count = 0 While 1 If $count = 0 Then $mouse = MouseGetPos() Sleep (10) ; to reduce CPU overload $button4 = PixelGetColor($coord4, 606) If $button4 = $color Then MouseClick("left", $coord4 + 30, 625, 1, 0) ; use fastest click $count += 1 ContinueLoop EndIf $button3 = PixelGetColor($coord3, 606) If $button3 = $color Then MouseClick("left", $coord3 + 30, 625, 1, 0) ; use fastest click $count += 1 ContinueLoop EndIf $button2 = PixelGetColor($coord2, 606) If $button2 = $color Then MouseClick("left", $coord2 + 30, 625, 1, 0) ; use fastest click $count += 1 ContinueLoop EndIf $button1 = PixelGetColor($coord1, 606) If $button1 = $color Then MouseClick("left", $coord1 + 30, 625, 1, 0) ; use fastest click $count += 1 EndIf WEnd “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JJ1122 Posted October 21, 2020 Author Share Posted October 21, 2020 30 minutes ago, Nine said: Remove useless call to PixelGetColor : Thank you for the simpler code ! It runs much faster, but makes some mistakes tho... Like pressing 3 before 4. I'm not sure why Link to comment Share on other sites More sharing options...
JockoDundee Posted October 21, 2020 Share Posted October 21, 2020 You may need to set these opt parameters to higher than 10 milliseconds: MouseClickDelay Alters the length of the brief pause in between mouse clicks. Time in milliseconds to pause (default=10). MouseClickDownDelay Alters the length a click is held down before release. Time in milliseconds to pause (default=10). Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
JJ1122 Posted October 21, 2020 Author Share Posted October 21, 2020 17 minutes ago, JockoDundee said: You may need to set these opt parameters to higher than 10 milliseconds: MouseClickDelay Alters the length of the brief pause in between mouse clicks. Time in milliseconds to pause (default=10). MouseClickDownDelay Alters the length a click is held down before release. Time in milliseconds to pause (default=10). Will it stabilize the clicks? What happens if I make them 0? Link to comment Share on other sites More sharing options...
Nine Posted October 21, 2020 Share Posted October 21, 2020 If changes happen really really fast, then there is no way to ensure that while you are clicking 3 that 4 should be clicked before. It is just a question of nano seconds, and then you are doom to fail. Ensuring a true solution will require more info and a decisive replicable environment. JockoDundee 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted October 21, 2020 Share Posted October 21, 2020 (edited) 2 hours ago, JJ1122 said: Will it stabilize the clicks? What happens if I make them 0? The control may need time to respond to the click message. But wait a second, do the buttons change color when clicked? If you are relying on that fact to know whether to click or not, and you don’t give any delay after clicking, you will end up with all sorts of crazy results. For instance, you could easily click a button twice because it has not been redrawn yet. I’m with @Nine, more info on what exactly this “electric circuit management” app is doing is needed, and why sub-second response is critical. The idea would be NOT to make them 0, but to make them greater than 10, the default. 10 milliseconds is really short, trust me a normal app can spare 100ms without any significant delay. Edited October 21, 2020 by JockoDundee Added part about making it 0 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
JJ1122 Posted October 30, 2020 Author Share Posted October 30, 2020 On 10/22/2020 at 6:36 AM, Nine said: If changes happen really really fast, then there is no way to ensure that while you are clicking 3 that 4 should be clicked before. It is just a question of nano seconds, and then you are doom to fail. Ensuring a true solution will require more info and a decisive replicable environment. On 10/22/2020 at 7:47 AM, JockoDundee said: The control may need time to respond to the click message. But wait a second, do the buttons change color when clicked? If you are relying on that fact to know whether to click or not, and you don’t give any delay after clicking, you will end up with all sorts of crazy results. For instance, you could easily click a button twice because it has not been redrawn yet. I’m with @Nine, more info on what exactly this “electric circuit management” app is doing is needed, and why sub-second response is critical. The idea would be NOT to make them 0, but to make them greater than 10, the default. 10 milliseconds is really short, trust me a normal app can spare 100ms without any significant delay. Thank you for the suggestions! Guess I'll need to think more about how to solve this myself/ Getting close tho. 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