Search code examples
javawindowsscriptingmouseoverwindows-scripting

Mouse shows color


i am trying to make an application which would show which color my mouse is pointing to, i dont mean in my own application but anywhere in windows on any screen, kind of like a tag beside my mouse pointer which shows the exact color.

example

I am a Java developer but i dont think this could be done in java i am thinking maybe i need some sort of script but i have no idea any help would be really appriciated


Solution

  • The solution consists of two parts:

    Part 1: Retrieving the color:

    Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
    Color color = new Robot().getPixelColor(mouseLocation.x, mouseLocation.y);
    

    Part 2: Getting the color name:

    You can get a list of many colors and their names from Wikipedia's List of colors. You can create a mapping in Java given the data on Wikipedia.

    Perhaps you can start with a few colors, and provide a generic hex representation for unknown colors, for example #rrggbb.