Jakob
Jakob

Reputation: 982

java - get mouse events outside of a component

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?

Upvotes: 4

Views: 3761

Answers (2)

stacker
stacker

Reputation: 69002

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

Upvotes: 2

Suraj Chandran
Suraj Chandran

Reputation: 24801

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.

Upvotes: 0

Related Questions