java - 获取组件外部的鼠标事件

发布于 2024-08-18 16:13:27 字数 214 浏览 4 评论 0原文

我和这里的人有同样的问题这里,因为我需要在 OS X 上拖动框架时跟踪框架位置。问题尚未解决,因此:

我如何告诉框架鼠标按下事件发生在其(操作系统本机)标题栏上,或者更一般地说,鼠标按下事件发生在屏幕上的某个地方?

i'm having the same issue as the person here, in that i need to track a frame location while it is being dragged on OS X. The question had not been resolved there, so:

how do i tell a frame that a mouse down event happened on its (OS-native) title bar or, more generally, that a mouse down event happened somewhere on the screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

池予 2024-08-25 16:13:27

从java 1.5开始

import java.awt.MouseInfo;

public class Mouse {
    public static void main(String[] args) {
        while ( true ) {
            System.out.println( MouseInfo.getPointerInfo().getLocation() );
        }
    }
}

编辑:

本机键盘鼠标挂钩

http://www.jotschi.de/?p=90

Since java 1.5

import java.awt.MouseInfo;

public class Mouse {
    public static void main(String[] args) {
        while ( true ) {
            System.out.println( MouseInfo.getPointerInfo().getLocation() );
        }
    }
}

EDIT:

Native keyboard mouse hook

http://www.jotschi.de/?p=90

随波逐流 2024-08-25 16:13:27

使用纯 Java,您永远无法判断鼠标按下事件发生在其(操作系统本机)标题栏上,或者在这种情况下发生在应用程序窗口之外的任何事件(不包括标题栏)。

重要的是要了解,作为 AWT/Swing 中的程序员,您的上下文、领域和权力仅位于应用程序窗口内。
最好的办法是使用 JNI。

Using pure Java, you can never tell that a mouse down event happened on its (OS-native) title bar, or for that case any event outside you application window(excluding title bars).

It's important understand that as a programmer in AWT/Swing your context and realm and power lies only within the application window.
Best shot is to use JNI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文