Colour under cursor?

Hello,
Is it possible for my Xojo app to be able to detect the Hexadecimal value of the colour below my mouse cursor, when the cursor is outside of my app (basically anywhere on the screen)?

Could someone point me in the right direction to where I would begin.

Thank you all in advance.

Take a screenshot and save it in a picture, then read the pixel’s color in the MouseX, MouseY position. That’s the general idea.

If you use a screenshot function like ScreenshotRectMBS you can get a screenshot from a pixel.
Be aware of color space conversions.

Thanks, but I think I will put this off for a while, it’s a bit beyond my capabilities at the moment :frowning:
Thank you anyway.

Hi Richard,

which platform?

OS X

No luck then. I may have some code to take screenshot in windows, but not OS X, sorry.

Julen

//capture screen dim susan as new shell susan.execute("screencapture -c -x") susan.Close cc = new clipboard

cc will contain the screen picture, available through cc.Picture

To obtain a portion of the screen, use graphics.DrawPicture http://documentation.xojo.com/index.php/Graphics.DrawPicture

Thanks Michel.
I am still a bit confused on that, but when I eventually get around to attempting this - I will take a deeper look.
Thank you for trying to help - I appreciate it. :slight_smile:

Sample project using Michel’s method:
https://www.dropbox.com/s/jykh8sybjd558so/color%20under%20mouse.xojo_binary_project

Edit: To use - make sure the app has focus then press the return/enter key to trigger the button. The code will break into the debugger at the break point with a variable containing the color. You could copy the code in the Action event of the button into a method which is called by whatever needs to determine the color.

Jason - thank you so much, I will study that and work out what is happening, and learn from it :slight_smile:

Just one question - if I move my mouse over a window of another app, and then press enter, the colour copied to the clipboard is the colour of my wallpaper, and not of the window colour?

Is that expected behaviour?
It seems to ignore everything on my screen except the wallpaper.

Thanks.

That’s interesting - it worked when I tried it with Safari and Xojo. Maybe take a look at the picture from the clipboard, p, and see if it is capturing the screen as expected or just your wall paper?

Jason,
I put my mouse over a blue coloured button on a window of another app, and then pressed enter.

I just pasted the clipboard content into an empty text file, and an image of my entire screen was pasted in.

When I look at the debugger however - I see the following:
This seems to have copied the green from the part of my wallpaper which was below the blue button??

Upon further testing, you are correct. It seems mousex and mousey are not returning the true mouse coordinates. This is fixed by changing the mousex and mousey to system.mousex and system.mousey.

I updated the sample project to reflect this and added a canvas to show the color so you don’t have to break into the debugger.

Thanks.

Why does the hexadecimal triplet value contain 2 extra 00 at the end?
C = &c20260000 instead of &c202600??

Is it possible for C to return JUST the hexadecimal code, such as: 202600

Thanks.

The 00 at the end is for the alpha channel (transparency) of the color.

you really want to launch a shell tool, edit the clipboard and take a full screenshot just for getting one pixel?
Sounds like a big waste of resources and users may blame you for altering their clipboard…

I looked on the MonkeyBread web site for it but could not locate it.

[quote=101583:@Christian Schmitz]Sounds like a big waste of resources and users may blame you for altering their clipboard…
[/quote]

Looks like overkill indeed, but it works. And the content of the current clipboard can be saved before starting the method, then restored afterwards.

Picture plugin.
Docs are here:
http://www.monkeybreadsoftware.net/pluginpart-screenshot.shtml