吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 344|回复: 4
收起左侧

[Java 原创] Java鼠标坐标和屏幕取色器

[复制链接]
yugeweida 发表于 2025-3-25 16:23
本帖最后由 yugeweIDA 于 2025-3-27 09:37 编辑

基于JAVA鼠标坐标和屏幕取色器有时用不到文字识别定位,需要临时做个简单的重复操作机器人,需要取鼠标坐标,用java自己做了个工具,顺带加了一个取色器的功能,偶尔参考别人UI配色用得着
新人第一帖,没啥干货分享个小工具哈,各位大佬多多关照!

[Java] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.example;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
 
public class MousePositionGui {
    private static Robot robot;
    public static void main(String[] args) {
        JFrame frame = new JFrame("获取鼠标位置");
        JLabel label = new JLabel("鼠标位置: ");
        frame.setSize(400, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new FlowLayout());
        frame.add(label);
        frame.setVisible(true);
        try {
            robot=new Robot();
        } catch (AWTException e) {
            throw new RuntimeException(e);
        }
        new MyThread1(label, frame).run();
    }
    private static void updateMousePosition(String msg, JLabel label) {
 
        label.setText(msg);
    }
    private static Color getColorAtPoint(Point p) {
        BufferedImage screenCapture = robot.createScreenCapture(new Rectangle(p.x, p.y, 1, 1));
        Color color = new Color(screenCapture.getRGB(0, 0));
        return color;
    }
 
    static class MyThread1 extends Thread {
        JLabel label=null;
        JFrame frame=null;
        public MyThread1(JLabel label,JFrame frame) {
            this.label=label;
            this.frame=frame;
        }
 
        public void run() {
            while (frame.isVisible()) {
                try {
                    Point location = MouseInfo.getPointerInfo().getLocation();
                    final Color color = getColorAtPoint(location);
                    updateMousePosition("<HTML>鼠标位置: x = " + location.getX() + ", y = " + location.getY()
                            +"\n<br>颜色RGB: " + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue()
                            +"</HTML>"
                            , this.label);
                    Thread.sleep(100); // 0.1秒执行一次
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
微信图片_20250325162300.png

positionTool.zip

3.58 KB, 下载次数: 5, 下载积分: 吾爱币 -1 CB

打包好的,双击直接用

免费评分

参与人数 1吾爱币 +5 热心值 +1 收起 理由
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

linlin01 发表于 2025-3-27 08:57
代码很强大,也很实用,有成品就更棒了
 楼主| yugeweida 发表于 2025-3-27 09:38
robert1234 发表于 2025-3-28 08:50
rust2tsur 发表于 2025-4-6 12:01
效果不错zsbd
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-4-23 22:51

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表