Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPixelColor() doesn't work correctly if Windows display scale is not 100% #403

Open
pixelart7 opened this issue Jun 20, 2018 · 2 comments

Comments

@pixelart7
Copy link

pixelart7 commented Jun 20, 2018

getPixelColor() doesn't work well with high density display on Windows 10 (possibly on others system as well.) The function seems to use given x, y coordinate and match with the original resolution.

For example, my real screen size is 1920*1080, scaled to 125% in Windows setting. Robotjs reports screen size as 1536*864, and function like moveMouse(x, y) works correctly with coordinate within 1536*864, ie, moveMouse(1536, 864) moved the mouse to bottom-right (real-screen pos: 1920, 1080).

Expected Behavior

getPixelColor() use coordinate after scaled
Example: getPixelColor(1536, 864) return color at (1920, 1080) real-screen pos
(using 1920*1080 screen with 125% scale)

Current Behavior

getPixelColor() use coordinate before scaled
Example: getPixelColor(1536, 864) return color at (1536, 864) real-screen pos
(using 1920*1080 screen with 125% scale)

Imgur
^ color at mouse position is wrong

Imgur
^ after moving a little bit down and right, the color return correctly

Possible Solution

Maybe fix in lower level files?
But I have some workaround, that kinda fix it in the top-left area, just in case someone want the half-baked solution:

// x, y parameters are in range from 0 to getScreenSize()
function getPixelColor(x, y) {
  var DIM = {
    X: 1920,
    Y: 1080,
  };
  var robotScreen = robot.getScreenSize();
  var robotx = x / robotScreen.width * DIM.X;
  var roboty = y / robotScreen.height * DIM.Y;
  return robot.getPixelColor(robotx, roboty);
}

Imgur
^ after the workaround

Steps to Reproduce (for bugs)

  1. Set scale of your Windows machine to more than 100%
  2. Try getPixelColor()

Your Environment

  • RobotJS version: 0.5.1
  • Node.js version: 8.9.4
  • npm version: 5.6.0
  • Operating System: Windows 10 version 1803 build 17134.112
@Catatomik
Copy link

Catatomik commented Aug 26, 2019

Just to clarify, because I had to search a while before finding this issue

Using this code to save the captured screen, we can have a better idea of the behavior.

  • This is with a 100% scale :

100%

  • This is with a 125% scale :

125%

So if you want to get, for example, the pixel color of a pixel in the bottom-right corner, it won't be possible.

@ricardopolo
Copy link

If you have issues like this, it is because Windows don't give apps the correct resolution. Windows lies to old apps about the resolution to prevent compatibility issues.

To fix this issue and make robotjs capture the whole screen, get the correct resolution, or get the correct pixel position, in High DPI/Scaled screens you should add and app manifest like this:

https://gist.github.com/ricardopolo/3fc7e6f0fbd7ef30f701e2d904abfd9f

With this Windows will disable the virtualization of the resolution, and give you the raw information.

In case you don't compile your app to and exe, with tools like pkg or nexe, you would need to add the manifest to the node.exe file in your system

Finally, if you don't know how to add a manifest to your app use rcedit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants