Jump to content

PixelGetColor isn't working on a specific computer

Recommended Posts

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.

#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")

Func GetPosition()
   $mPos = MouseGetPos()
   $gPos0 = $mPos[0]
   $gPos1 = $mPos[1]
   MsgBox(0, "", $gPos0 & ", " & $gPos1)

Func GetColor()
   $gColor = Hex(PixelGetColor($gPos0, $gPos1))
   MsgBox(0, "", $gColor)


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.



I'd really appreciate if anyone helps me with this nonsense. Thanks!

Link to post
Share on other sites
  • Moderators


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.


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Link to post
Share on other sites
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 post
Share on other sites
  • Developers
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. ;) 

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 post
Share on other sites
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.


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...