tonycst Posted April 27, 2018 Posted April 27, 2018 (edited) This is an old problem i cannot resolve to this day. Code works for windows 7 but not for 10. Confirmed on multiple machines. It does not find the color unless its in the upper left area of the screen. Found color returns wrong coordinates. Also, AU3Info behaves exact same way. It does not pick up the color i am looking for. Color return value is completely wrong, not even close. For example salad green color returns completely different result (see picture attached) See code below. Pretty basic. Instructions for testing Save screenshot to your desktop and name it "Censitrac.jpg" Right click on jpg file and select "Edit" to open it with MS pain. Picture viewer will not work. Pixelsearch will not work with PhotoViewer as far as i know from past experience. Run the code. Press Enter to start searching for the green color (green square with + sign inside) Once found, mouse will move there and click, leaving a painted dot giving you visual indication where it found the color. The Input area is for how many times you want it to click on a found pixel. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=notify.ico #AutoIt3Wrapper_Outfile=C:\Users\Administrator\Desktop\CensiSambler.Exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <GuiEdit.au3> #include <File.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <Sound.au3> #include <Misc.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> Global $PixelColor = 0x54B359 ;greenish Global $GUI Global $Input Global $WindowToSearch = "Censitrac" Global $hDLL = DllOpen("user32.dll") Opt("TrayOnEventMode", 1) ;to go to function on click Opt("TrayAutoPause", 0) Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Opt("PixelCoordMode", 1) ;0 search based on window position. 1 screen. 2 relative to window TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "_Exit") _Main() Func _Main() #Region ;GUI Elements $GUI = GUICreate("Sencitrack Assembler", 40, 70,@DesktopWidth-40,@DesktopHeight/2,$WS_POPUP,$WS_EX_TOPMOST) $Input = GUICtrlCreateInput ("",0,0,40,30) GUICtrlSetFont (-1,15,20) $Auto = GUICtrlCreateButton ("Auto",0,30,40,40) GUICtrlSetFont (-1,10,20) GUISetState(@SW_SHOW, $Gui) #EndRegion ;GUI Elements While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then DllClose($hDLL) Exit EndIf If WinActive($Gui) > 0 And _IsPressed("0D", $hDLL) = 1 Then ;Start search ENTER was pressed _Search() GUICtrlSetData ($Input,"") EndIf If $msg = $Auto Then ;autoatic function EndIf WEnd EndFunc ;==>_Main Func _Search() If WinExists($WindowToSearch) = 1 Then While 1 $WindowHandle = WinGetHandle ($WindowToSearch) If @error Then ExitLoop WinActivate($WindowHandle) If _IsPressed("1B", $hDLL) = 1 Then Exit ;if escape is pressed $WindowHandle = WinGetHandle ($WindowToSearch) $WinPos = WinGetPos ($WindowToSearch) $X= $WinPos[0] $Y =$WinPos[1] $Search = PixelSearch($X,$Y,1920,1080, $PixelColor, 2, 1,$WindowHandle) ;2 for shade variation,1 for steps, and window name to search If IsArray($Search) = True Then ConsoleWrite (@crlf & "Found it at X=" & $Search[0]& " Y=" & $Search[1] & " WinPos " & $X & " " & $Y) WinActivate ($WindowHandle) MouseClick ($MOUSE_CLICK_LEFT,$Search[0],$Search[1],1,0) sleep (3000) Else ConsoleWrite (@crlf & "nothing found at winpos " & $X & " " & $Y) sleep (1000) Endif WEnd ConsoleWrite (@crlf & "Done") Else ;window does not exist so give warning ConsoleWrite (@crlf & "Window does not exst") EndIf EndFunc Func _Exit() Exit EndFunc ;==>_Exit Edited April 27, 2018 by tonycst
IAMK Posted April 27, 2018 Posted April 27, 2018 https://www.pcworld.com/article/2953978/displays/use-windows-10s-individual-display-scaling-to-perfect-your-multi-monitor-setup.html
tonycst Posted April 27, 2018 Author Posted April 27, 2018 Never thought Windows 10 has it set to 125 by default. Never the less. this is a serious issue that needs to be addressed and perhaps fixed. Thank you. This was giving me cancer symptoms for too long. I hope someone would put a stop to that because as of right now, 99.99% of all PC's today are likely to have their DPI set to 125% as well. Help me with the temporary fix now. Can the DPI be detected with autoit ? How would i implement that into my function to compensate for that until they fix pixelsearch function (because it needs to have this problem solved one way or another)
IAMK Posted April 27, 2018 Posted April 27, 2018 (edited) The pixel colour you want is pixel/125*100. However, I don't know how much this can be trusted. You could maybe write a script which sets the DPI to 100%. Run that before running this. Edited April 27, 2018 by IAMK
TheXman Posted April 27, 2018 Posted April 27, 2018 See if adding the A3Wrapper directive helps: #AutoIt3Wrapper_Res_HiDpi= Y ;(Y/N) Compile for high DPI. Default=N CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
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