I’d like to know how I can code a Java program that knows which Windows application is in focus. I can have many windows open but I want to know the one that’s being used (like Google Chrome right now as I’m typing this).
I don’t need to change anything in the window or application, just need to know its name.
I’m afraid there’s no java api for that. JVM does not know anything about the windows it does not manage. You’ll probably have to use JNI and call this function
MSDN link
PS. THere is a
GetWindowTextfunction that you might want to use if you need to grab the title of the window.This post has JNI examples that might be helpful for you.