0

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.

1 Answers1

0

No, there is no cross-platform solution for that. Each platform has it's own window system, and linux has 2: Wayland and XOrg. This question is not related to kotlin or kotlin multiplatform. Search it for java, for example Get current active window's title in Java

gavr
  • 807
  • 7
  • 16