For example the following code snippet does just that but only for Windows:
import com.sun.jna.platform.win32.User32
import com.sun.jna.platform.win32.WinDef.HWND
object ActiveWindowFinder {
@JvmStatic
fun main(args: Array<String>) {
var count = 0
while (true){
val hwnd: HWND = User32.INSTANCE.GetForegroundWindow()
val title = CharArray(150)
User32.INSTANCE.GetWindowText(hwnd, title, 150)
println("Active window title: ${String(title).trim()}")
count ++
Thread.sleep(200)
if (count == 100){
break
}
}
}
}
I need a way of getting the same behaviour on Mac and on Linux.