1

I want my program to detect if the mouse is pressed down anywhere on the Screen and not just the program window. It should also detect when the mouse is being released. Is it possible in Java to detect this outside of my program window?

luator
  • 4,769
  • 3
  • 30
  • 51

2 Answers2

0

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.

  • I'm asking for mouse presses.... Look what this guy wrote: You will only receive mouseMoved events, never mouseDragged events. That's because there is no way to receive information about clicks outside the main window. –  Aug 07 '18 at 13:45
  • @AllesLegit try to use a `MouseListener` instead you can find it [here](https://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseListener.html) – user12346352 Aug 07 '18 at 13:53
  • @MartinŠpelina why don't you tell him that before? he wrote in his Question that he Needs a mousepressed and released – user12346352 Aug 07 '18 at 13:56
-1

Maybe you should look at the Java Native Hook for Global Mouse and Key Listeners

Gareth
  • 11
  • 2
  • 8