简体   繁体   English

如何注册MousemotionListener

[英]How to register MousemotionListener

How to Register MouseMotionListener without using Applet,JFrame,JPanel or anything.Because i want to capture mouse positions when mouse is just moved in a System? 如何在不使用Applet,JFrame,JPanel或任何东西的情况下注册MouseMotionListener。因为当鼠标在系统中移动时,我想捕获鼠标位置?

import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.*;
import java.awt.*; 
class Mouseposition extends MouseAdapter
{
public void mouseMoved(MouseEvent e)
{
System.out.println("MOuse x : "+MouseInfo.getPointerInfo().getLocation().x+ "Mouse Y : "+MouseInfo.getPointerInfo().getLocation().y);
}
public static void main(String args[])
{
//--- register for Mouse events
----
while(true);
}
}

You can't, Java won't listen to global OS events in this way. 您不能,Java不会以这种方式监听全局OS事件。

You could use a JNI/JNA hook into the OS, for example or example or use a Thread to constantly poll the MouseInfo class, for example and example , which probably isn't very efficient... 你可以使用JNI / JNA钩到操作系统中, 例如例如 ,或者使用一个Thread ,不断轮询MouseInfo类,用于例如例如 ,这可能也不是很有效的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM