octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.37k stars 961 forks source link

Not getting actual window color #596

Open pralay03 opened 4 years ago

pralay03 commented 4 years ago

When trying to get pixel color from the desktop, it only returns the pixel color from the desktop background image/wallpaper. Any window or app etc color is always ignored.

I am not sure what I am missing here. Any help is really appreciated.

Screenshot 2020-08-17 at 1 15 48 AM

Expected Behavior

Get the pixel color from anything under the mouse. In my case, color from app UI, see red circle on the screenshot.

Current Behavior

Getting the pixel color from only the desktop background image. Any window, app icons, etc are ignored.

Steps to Reproduce (for bugs)

Here is my code:

function colorEyeDropper(){

        ioHook.disableClickPropagation();
        ioHook.on('mouseclick',  process_iHook_mouseClick);
        ioHook.start();
      }

function process_iHook_mouseClick(){

        var mouse = robot.getMousePos();
        var hex = robot.getPixelColor(mouse.x, mouse.y);
        console.log("#" + hex + " at x:" + mouse.x + " y:" + mouse.y);

        ioHook.enableClickPropagation();
        ioHook.removeListener('mouseclick', process_iHook_mouseClick);
       }

Context

I am creating a color eyedropper tool for adobe app. It will pick color from anywhere on the desktop.

Your Environment

luke-j commented 4 years ago

For anyone coming to this issue in the future. The solution involves granting access to the terminal/application running robotjs via Settings > Security & Privacy > Privacy > Screen Recording.