简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM