Thomas Nappo
Thomas Nappo

Reputation: 251

Java Get Focused Window

How would I get the currently focused window in Java? For example, if the user is in Google Chrome. I believe this requires native code, and I've never used native code, so please help out with that.

I only need this to work with Windows, so I think this might be possible with a VB script?

Upvotes: 1

Views: 1725

Answers (1)

Zentdayn
Zentdayn

Reputation: 62

I am not familiar with vb, but you might be looking for:
GetForegroundWindow-that should give you the "window with which the user is currently working"
GetWindowText-to get the title

correct me if im wrong but i believe you could load "User32.dll" from VB to use this, a quick google search gave me some examples of it, they should help you. ( you will have to de the searches yourself, i cant post more than 2 links and those two seems to be the most important)

Edit: Since you tagged this as JNI you could write it C/C++ and use them from Java. Since those functions are part of the windows API there might be already something ready to use with java.

Similar question that might have better answers:Get current active window's title in Java

Upvotes: 1

Related Questions