Skip to content

Instantly share code, notes, and snippets.

@win0err
Last active December 22, 2017 12:14
Show Gist options
  • Save win0err/d6293b5cd62d5fcbecd587680c0eaca0 to your computer and use it in GitHub Desktop.
Save win0err/d6293b5cd62d5fcbecd587680c0eaca0 to your computer and use it in GitHub Desktop.
import java.awt.Color;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.MouseInfo;
import java.awt.Point;
public class ColorPicker {
public static void main(String[] args) {
System.out.println("Press Ctrl+C to exit");
while(true) {
try {
Robot robot = new Robot();
Point p = MouseInfo.getPointerInfo().getLocation();
Color color = robot.getPixelColor(p.x, p.y);
System.out.print(
"Color: " + color.getRed() + " "
+ color.getGreen() + " "
+ color.getBlue()
+ " \r");
} catch (AWTException e) {
System.out.println("Can't run at headless environment");
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment