首页 > 解决方案 > Java - 检测鼠标是否在屏幕上的任何位置按下

问题描述

我希望我的程序检测鼠标是否在屏幕上的任何位置按下,而不仅仅是程序窗口。它还应该检测鼠标何时被释放。在 Java 中是否可以在我的程序窗口之外检测到这一点?

标签: javaswingmouseeventdetectawtrobot

解决方案


java.awt.event.MouseMotionListener is only going to give you information about mouse movement inside your application window. For events that occur outside that window, there is no way around MouseInfo.getPointerInfo. This is a duplicate of Java mouse motion anywhere on screen.


推荐阅读