Jumbala
Jumbala

Reputation: 4944

Listener for when the user changes window (not necessarily windows created by the application)

I need to add a functionality in my application that would require me to know when the user changes window (it could be a browser window, my application's window or any other window).

Ideally, it should be possible for me to print the window's title when it gets focus. The problem I'm having finding a solution to this problem is that I only get links that tell me how to add a focus listener on windows I'm creating, which I already know how to do and doesn't help me in the slightest.

The solution should at least work on Windows 7.

Upvotes: 0

Views: 201

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347194

The (major) problem you face is that Java filters system events so that you can only recieve events that are related to you. AFAIK this is all done at a native level, so there's no way to intercept or modify this filtering process.

The only solution is to create another "event loop" using JNI/JNA which will allow you to intercept the event messages being passed about the system and handle them the way you want to.

While slightly more complicated, it does open up a world of opportunities...

Upvotes: 1

Related Questions