StudentJack Posted October 24, 2018 Share Posted October 24, 2018 Hello, At the beggining I have to say "Hello" to everyone. It's my first post here. I am student and I got an exercise from my teacher (He is active member here, so if you reading this, don't lower my grade please ^^ ) I have to write program that click on dots in MSPaint. Here it is visualisation how it should work. (image) Teacher makes dots in random places on screen in MSPaint, and my code has to click each and then click them backward. Okey. That's all about how it should work. Now the part what I did figuret out: local dots[] = [] $dot = PixelSearch(0,90,1365,650,0x000000) If Not @error Then MouseClick("Left",$dot[0],$dot[1],1,10) EndIf I don't know how exacly should I add the position of the each dot ( or I shouldn't ?) . It's strange for me - I mostly code in Java. Is there any library that I can use? Thanks for help. ~StudentJack caramen 1 Link to comment Share on other sites More sharing options...
careca Posted October 25, 2018 Share Posted October 25, 2018 (edited) Hi, this is interesting, there are probably lots of ways to do it, but i think my approach would start by looping the pixelsearch until i got all points, somehow ignore points too close to each other, meaning pixels around a specific pixel, because what you have there is a circle with lots of black pixels. When i say somehow, i mean maybe add those points into an exclusion list if the difference between x1 and x2 < 10px or so. After i got all the points, i'd sort them by the X coordinate, then loop through them with the mouse click, reverse sort, and then click all back. Edited October 25, 2018 by careca Xandy 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
junkew Posted October 25, 2018 Share Posted October 25, 2018 Tell us how you would do it in Java then we can guide you with the functions you need in AutoIt (without giving the full exercise answer ;-)) Earthshine and mLipok 2 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
mLipok Posted October 25, 2018 Share Posted October 25, 2018 @StudentJack to the forum. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
StudentJack Posted October 25, 2018 Author Share Posted October 25, 2018 I tried to figure it out, so I wrote this code and found out something weird. PixelSearch - searches the nearest point to x1 and x2 (PixelSearch(x1,x2)). My code: Global $Paused HotKeySet('{Insert}','TogglePause') WinActivate("dots - Paint") Func FindDot() $dot = PixelSearch(8,146,1187,613,0x000000) $nextdot = PixelSearch(8,146,1187,613,0x000000,0,10) If @error Then Exit Else MouseMove($nextdot[0],$nextdot[1],10) EndIf EndFunc While 1 FindDot() WEnd Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) WEnd EndFunc In Java: I'd get mouse cords every time I found the black dot, then add it to the table, stop the loop while it's on first dot and then search for another and again. In autoit I have found something like "Imagesearch" ? Maybe it's better to use than PixelSearch? @mLipok Hello Link to comment Share on other sites More sharing options...
JoHanatCent Posted October 25, 2018 Share Posted October 25, 2018 Try searching from left to right? Global $Paused HotKeySet('{Insert}', 'TogglePause') WinActivate("dots - Paint") $dot = 1 $count = 1 While $count < 1187 $dot = PixelSearch(8 + $count, 146, 8 + $count, 613, 0x000000) If Not @error Then MouseMove($dot[0], $dot[1], 50) MouseClick("Left", $dot[0], $dot[1], 1, 10) EndIf $count = $count + 4 WEnd Func TogglePause() $Paused = Not $Paused While $Paused Sleep(100) WEnd EndFunc ;==>TogglePause StudentJack 1 Link to comment Share on other sites More sharing options...
StudentJack Posted October 25, 2018 Author Share Posted October 25, 2018 Okey. That's nice, thanks @JoHanatCent. So if I'd like to make it search from left to right and when there is no more black dots, start searching from right to left I need to change this: (?) Global $Paused HotKeySet('{Insert}', 'TogglePause') WinActivate("dots - Paint") $dot = 1 $count = 1 ; =>change here to 1187 While $count < 1187 ; => and here to 8? ; and then $dot would looks like this: ; $dot = PixelSearch(0 + $count, 613, 0 + $count, 146, 0x00000) $dot = PixelSearch(8 + $count, 146, 8 + $count, 613, 0x000000) If Not @error Then MouseMove($dot[0], $dot[1], 50) MouseClick("Left", $dot[0], $dot[1], 1, 10) EndIf $count = $count + 4 WEnd I understand the point? Link to comment Share on other sites More sharing options...
junkew Posted October 25, 2018 Share Posted October 25, 2018 Faq 38 Will teach you more on bitmaps you can get with windows gdi functions. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
JoHanatCent Posted October 26, 2018 Share Posted October 26, 2018 " .. how can I make it search for dots from Left to Right after script finished searching from right to left? .." You can change this : While $count < 1187 to While 0. The counter then needs to be changed to minus when going over 1187 until you get back to less than 8. As soon as it gets to 8 change the counter to positive again? Link to comment Share on other sites More sharing options...
careca Posted October 26, 2018 Share Posted October 26, 2018 (edited) #include<Misc.au3> WinActivate("[CLASS:MSPaintApp]") Global $WPos = WinGetPos("[CLASS:MSPaintApp]") Global $dot = 0, $h = $WPos[1] + 155 While 1 If _IsPressed('1B') Then Exit EndIf For $i = 1 To 2 If $i = 1 Then For $w = $WPos[0] + 15 To $WPos[2] Step 10 $dot = PixelSearch($w, $h, $w+10, $WPos[3], 0x000000, 0, 2) If Not @error Then MouseMove($dot[0], $dot[1], 5) EndIf Next Else For $w = $WPos[2] To $WPos[0] + 15 Step -10 $dot = PixelSearch($w, $h, $w-10, $WPos[3], 0x000000, 0, 2) If Not @error Then MouseMove($dot[0], $dot[1], 5) EndIf Next EndIf Next WEnd EDIT corrections Edited October 26, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
StudentJack Posted October 29, 2018 Author Share Posted October 29, 2018 Thank you @careca, @JoHanatCent, @junkew for help! You guys awesome! Link to comment Share on other sites More sharing options...
Juvigy Posted October 29, 2018 Share Posted October 29, 2018 This is how i did that, but i dont know why it doesnt draw straight lines , but it curves at the second point ? HotKeySet("{ESC}", "Terminate") WinActivate("[CLASS:MSPaintApp]") Global $array[0] $hDLL = DllOpen("user32.dll") While 1 Sleep(10) If _IsPressed("01", $hDLL) Then $aPos = MouseGetPos() $string = _ArrayToString($aPos,".") _ArrayAdd($array,$string) Sleep(200) EndIf ;~ $dot = PixelSearch($w, $h, $w+10, $WPos[3], 0x000000, 0, 2) WEnd Func Terminate() DllClose($hDLL) ConnectDots($array) ;~ _ArrayDisplay($array,"$array") Exit EndFunc Func ConnectDots($arr) For $i=0 to UBound($arr) - 1 Step 1 If $i= UBound($arr) - 1 Then ExitLoop $test = StringSplit($arr[$i],".",2) $test2 = StringSplit($arr[$i+1],".",2) MouseClickDrag($MOUSE_CLICK_LEFT, $test[0],$test[1], $test2[0],$test2[1],30) Next EndFunc Link to comment Share on other sites More sharing options...
StudentJack Posted October 29, 2018 Author Share Posted October 29, 2018 (edited) Hello, Here's code that I used and there is result. Thanks to @careca. #include<Misc.au3> WinActivate("[CLASS:MSPaintApp]") Global $WPos = [5,143,823,630] Global $dot = 0, $h = $WPos[1] While 1 If _IsPressed('1B') Then Exit EndIf For $i = 1 To 2 If $i = 1 Then For $w = $WPos[0] + 15 To $WPos[2] Step 10 $dot = PixelSearch($w, $h, $w+10, $WPos[3], 0x000000, 0, 2) If Not @error Then MouseMove($dot[0], $dot[1], 5) EndIf Next Else For $w = $WPos[2] To $WPos[0] + 15 Step -10 $dot = PixelSearch($w, $h, $w-10, $WPos[3], 0x000000, 0, 2) If Not @error Then MouseMove($dot[0], $dot[1], 5) EndIf Next EndIf Next WEnd I've got another task and need a little more help ^^ . I do not want to start new thread so I will ask question here. I have to measure the distance from one dot to another and write the result. But it couldn't be so easy, so here is a catch! If the distance from mouse cord is less than 1, do not click this dot. Look for another that is further. I have an idea, that I will show to you guys. To calculate the distance we can use this: Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem for 2D Local $a, $b, $c If $x2 = $x1 And $y2 = $y1 Then Return 0 Else $a = $y2 - $y1 $b = $x2 - $x1 $c = Sqrt($a * $a + $b * $B) Return $c EndIf EndFunc ;==>Pixel_Distance The credits goes to @UEZ. I did not write it. To get the mouse cords, I can use: MouseGetPos Now I don't know exacly how to glue it into one. Script looks for dots and it's great. I definitly use it for finding dots, but now I have to calculate distance betwen this dots. @Edit Please look at this pseudocode, is my way of thinking right? $BlackDotCord $RedDotCord $OrangeDotCord ;First calculate distance black to orange. So xy,x1y1 should be $x = $BlackDotCord[0] $y = $BlackDotCord[1] $x1 = $OrangeDotCord[0] $y1 = $OrangeDotCord[1] $dist = Pixel_Distance($x,$y,$x1,$y1) If $dist < 1 Then MouseMove(~~? I have to store every distance in table? Edited October 29, 2018 by StudentJack ideas Link to comment Share on other sites More sharing options...
careca Posted October 30, 2018 Share Posted October 30, 2018 expandcollapse popup#include <Misc.au3> WinActivate("[CLASS:MSPaintApp]") Global $WPos = WinGetPos("[CLASS:MSPaintApp]") ConsoleWrite('$WPos[0] - ' & $WPos[0] & ' $WPos[1] - ' & $WPos[1] & ' $WPos[2] - ' & $WPos[2] & ' $WPos[3] - ' & $WPos[3] & @CRLF) Global $dot = 0, $h = $WPos[1] + 155 Global $xPrev = 0, $yPrev = 0, $PDist While 1 If _IsPressed('1B') Then Exit EndIf For $i = 1 To 2 If $i = 1 Then For $w = $WPos[0] + 15 To $WPos[2] Step 10 $dot = PixelSearch($w, $h, $w + 10, $WPos[3] - 30, 0x000000, 0, 1) If Not @error Then If $xPrev <> 0 Or $yPrev <> 0 Then Pixel_Distance($xPrev, $yPrev, $dot[0], $dot[1]) EndIf MouseMove($dot[0], $dot[1], 5) $xPrev = $dot[0] $yPrev = $dot[1] EndIf Next Else For $w = $WPos[2] To $WPos[0] + 15 Step -10 $dot = PixelSearch($w, $h, $w - 10, $WPos[3] - 30, 0x000000, 0, 1) If Not @error Then If $xPrev <> 0 Or $yPrev <> 0 Then Pixel_Distance($xPrev, $yPrev, $dot[0], $dot[1]) EndIf MouseMove($dot[0], $dot[1], 5) $xPrev = $dot[0] $yPrev = $dot[1] EndIf Next EndIf Next WEnd ;============================================================================= Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem for 2D Local $a, $b, $c If $x2 = $x1 And $y2 = $y1 Then Return 0 Else $a = $y2 - $y1 $b = $x2 - $x1 $c = Sqrt($a * $a + $b * $B) ConsoleWrite($c &@CRLF) Return $c EndIf EndFunc ;==>Pixel_Distance Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
caramen Posted October 31, 2018 Share Posted October 31, 2018 On 29/10/2018 at 9:36 PM, StudentJack said: To calculate the distance we can use this: Amazing... My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki 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