rm65453 Posted January 5, 2021 Posted January 5, 2021 Hi everyone, I am trying to find the location of all the pixels of a particular on the screen. In order for me to do that, I move the cursor to the color that I am selecting in ms-paint. Once I have done that, I draw a line on the screen and hope to catch the location of all the pixels but the script doesnt do anything once it gets to that point. Looking for some help here. #include <MsgBoxConstants.au3> Local $aArray[0] Sleep(5000) Local $aPos = MouseGetPos() Local $iColor = PixelGetColor($aPos[0], $aPos[1]) MsgBox($MB_SYSTEMMODAL, "", "The decimal color is: " & $iColor) ;MsgBox($MB_SYSTEMMODAL, "", "The hex color is: " & Hex($iColor, 6)) Sleep(5000) Local $aCoord = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $iColor) If Not @error Then MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1]) EndIf ;MouseMove($aCoord[0], $aCoord[1], 0) For $x = 0 To @DesktopWidth Step 1 For $y = 0 To @DesktopHeight Step 1 If PixelGetColor($x,$y) = $iColor Then ;Add $x and $y to Array using _ArrayAdd() (or whatever you prefer) MouseMove($x, $y, 10) _ArrayAdd($aArray, $x & "-" & $y) EndIf Next Next _ArrayDisplay($aArray, "Pixels")
Nine Posted January 5, 2021 Posted January 5, 2021 (edited) Your script is working for me (you need to add an #include tho). Not the most efficient, but it is working... ps. on Win10, it is terribly slow, maybe that is why you think nothing is happening... Edited January 5, 2021 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents 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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
rm65453 Posted January 5, 2021 Author Posted January 5, 2021 (edited) Is there a faster way to do this then? I need to run this on an ongoing basis to see if a new line has graphed on the screen. Also what is the #include that I am missing. <Array.au3>? edit: I added ConsoleWrite($x & "-" & $y & @LF) to the loop and its very very slow. Dont think this solution will work for my need. Edited January 5, 2021 by rm65453 additional detail.
Nine Posted January 5, 2021 Posted January 5, 2021 Well, that pixel search way is the worst way to automate an application. What is the true application you want to automate ? It is certainly not Paint ! “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents 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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
rm65453 Posted January 6, 2021 Author Posted January 6, 2021 (edited) No its not. I basically wanted to detect a zig zag line on a forex chart and find out the slope of the last drawn line. if its a positive or negative slope basically. What I was thinking was if I have the location of all the pixels on the screens that I can go from right to left to find the last pixel and then find the relative position of the pixel before that and detect the slop that way. Edited January 6, 2021 by rm65453
Nine Posted January 6, 2021 Posted January 6, 2021 Can you show me an example (print screen) of the window ? “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents 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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
MaximusCZ Posted January 6, 2021 Posted January 6, 2021 (edited) The default PixelGetColor is slow. To speed it up, take a look on those: With this, you can make in memory screenshot and traverse it pixel by pixel muuuch faster than with PixelGetColor. Also works if the window you monitor is in background! or here: or here: Edited January 6, 2021 by MaximusCZ
rm65453 Posted January 6, 2021 Author Posted January 6, 2021 On 1/6/2021 at 12:37 AM, Nine said: Can you show me an example (print screen) of the window ? Expand Please see screenshot attached. Looking to see if the last drawn line is up or down.
Nine Posted January 6, 2021 Posted January 6, 2021 Ok, I see. Since it is a totally static picture, I would take a screen capture of your window (_ScreenCapture_CaptureWnd) . Then use GDI+ to convert the bitmap into a scan memory (_GDIPlus_BitmapLockBits). And finally use that space in memory to locate pixel as you want to. The example of _GDIPlus_BitmapLockBits is close to what I am suggesting. You may also look at the previously mentioned UDF, there is probably some work that have already been done around this area. I made my own UDF (unpublished). It is not very complicated, but if you can use a UDF, it can serve as a basis for your own project. “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents 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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
rm65453 Posted January 6, 2021 Author Posted January 6, 2021 Thanks @Nine and @MaximusCZ going to try these approaches. If there are any additional code bits that you can share please do. Going to be working on these approaches now.
rm65453 Posted January 10, 2021 Author Posted January 10, 2021 (edited) expandcollapse popup#include <MsgBoxConstants.au3> #include <Array.au3> #include <String.au3> ; #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <FastFind.au3> #Include <WinAPI.au3> Opt("WinTitleMatchMode", 2) Local $aArray[0] Local $x Local $y Local $x2 Local $y2 Local $aCoords[0] Sleep(10000) Local $aPos = MouseGetPos() Local $iColor = PixelGetColor($aPos[0], $aPos[1]) ;Local $iColor = 9785202 ;Local $iColor = 15539236 MsgBox($MB_SYSTEMMODAL, "", "The decimal color is: " & $iColor & ". Monitoring zigzag lines.") ;MsgBox($MB_SYSTEMMODAL, "", "The hex color is: " & Hex($iColor, 6)) Local $hGUI = GUICreate("Signal Monitoring", 100, 100) Local $idButton = GUICtrlCreateButton("Monitoring", 10, 10, 80, 80) GUISetState(@SW_SHOW, $hGUI) Sleep(1000) While 1 Sleep (10000) $x = 0 $y = 0 $x2 = 0 $y2 = 0 FFSnapShot(0, 0, 0, 0) ;$aCoords = FFNearestSpot(4, 5 , @DesktopHeight, 0, 10, $iColor, False) $aCoords = FFNearestPixel(@DesktopHeight, 0, $iColor, False) If UBound($aCoords) = 0 Then GUICtrlSetData( $idButton, "Monitoring") Else ;_ArrayDisplay($aCoords, "Coordinates") $x = $aCoords[0] $y = $aCoords[1] ;MouseMove($x, $y, 10) $newx = $x - 20 $aCoords = FFNearestPixel($newx, $y, $iColor, False) ;$aCoords = FFNearestSpot(4, 5 , $newx, $y, 10, $iColor, False) ;_ArrayDisplay($aCoords, "Coordinates") ;$aCoords = FFNearestPixel($newx, $y, $iColor, False) $x2 = $aCoords[0] $y2 = $aCoords[1] ;MouseMove($x2, $y2, 10) ;MsgBox(0,"Coordinates", $x & "-" & $y & "--" & $x2 & "-" & $y2) If $y > $y2 Then GUICtrlSetData( $idButton, "Down") Else GUICtrlSetData( $idButton, "Up") EndIf EndIf WEnd This one is working but for some reason is unreliable and I cannot figure out why it works until I have 2 or 3 lines but then stops working. edit: seems like it works well if the lines are in the left half of the screens but not so well as it scrolls towards the right. Edited January 10, 2021 by rm65453 more details.
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