endtro Posted March 31, 2021 Share Posted March 31, 2021 Hello, there! For whatever reason PixelGetColor isn't working properly on my new Laptop. I did found out what's wrong, but don't understand why it's happening. So, it seems that AutoIt is analyzing the screen as if it's upscaled and/or has a weird offset. Here's a script that I used for testing purposes: F8 saves the mouse position, F9 saves the color of a pixel where F8 was pressed. After that I just wave the cursor around the screen, and if the color under the cursor matches the saved one, it plays the sound. Spoiler #include <MsgBoxConstants.au3> HotKeySet("{F8}", "GetPosition") HotKeySet("{F9}", "GetColor") Global $gPos0, $gPos1, $gColor While True Local $pos = MouseGetPos() If Hex(PixelGetColor($pos[0], $pos[1])) == $gColor Then SoundPlay ("C:\Windows\Media\Speech Misrecognition.wav") EndIf Sleep(500) WEnd Func GetPosition() $mPos = MouseGetPos() $gPos0 = $mPos[0] $gPos1 = $mPos[1] MsgBox(0, "", $gPos0 & ", " & $gPos1) EndFunc Func GetColor() $gColor = Hex(PixelGetColor($gPos0, $gPos1)) MsgBox(0, "", $gColor) EndFunc Also, here's the kind of paint images I used for testing. It turned out that PixelGetColor detects the green color in the area marked by the orange rectangle, not where it actually is. Spoiler I'd really appreciate if anyone helps me with this nonsense. Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 31, 2021 Moderators Share Posted March 31, 2021 endtro, Welcome to the AutoIt forums. This is no doubt a matter of a different display scaling on the affected computer. There are plenty of threads about this on the forum if you search. M23 endtro 1 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...
endtro Posted March 31, 2021 Author Share Posted March 31, 2021 46 minutes ago, Melba23 said: This is no doubt a matter of a different display scaling on the affected computer. There are plenty of threads about this on the forum if you search. Hey, thanks for a quick reply! So I did looks around the forum and the most I could get is to multiply my PixelGetColor coordinates by the scale factor. I did a bit of testing and unfortunately it doesn't seem like it's gonna work pixel perfect which is an issue for me. #include <WinAPIGdi.au3> Global $scale = _WinAPI_EnumDisplaySettings('', $ENUM_CURRENT_SETTINGS)[0] / @DesktopWidth ConsoleWrite("Scale = " & _WinAPI_EnumDisplaySettings('', $ENUM_CURRENT_SETTINGS)[0] & " / " & @DesktopWidth & " = " & $scale & @CRLF) Found this bit of code above by Malkey and tried to use it like this: PixelGetColor($pos[0] * $scale, $pos[1] * $scale) It does work for the most part, but not accurate enough. I tried to round the coordinates up and down as well but to no avail. Any other advises? I don't mean no disrespect, but do you know if AutoHotKey have this kind of an issue? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 31, 2021 Developers Share Posted March 31, 2021 6 minutes ago, endtro said: but do you know if AutoHotKey have this kind of an issue? Understand you don't mean to disrespect ...but this is not the smartest question in these forums and would advice you to go there. endtro 1 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...
rednaxela Posted April 1, 2021 Share Posted April 1, 2021 I had the same inssue and i decided make pixelsearch very small areas searching the same colors. That solved the problem of multiple computers. endtro 1 Link to comment Share on other sites More sharing options...
endtro Posted April 1, 2021 Author Share Posted April 1, 2021 14 hours ago, rednaxela said: I had the same inssue and i decided make pixelsearch very small areas searching the same colors. That solved the problem of multiple computers. That's actually a great idea! I've only noticed it occasionally skipping horizontal lines of pixels. I'm gonna have to check if it also skips vertical lines. Maybe I'll be able to get away with scanning 1x3 areas around the mouse cursor. Thanks! Link to comment Share on other sites More sharing options...
NIKHILSKYNET Posted October 8 Share Posted October 8 DllCall("User32.dll", "bool", "SetProcessDPIAware") This fixed the Problem For me when Display scaling is not 100% 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