Open up Touch Keyboard on Kotlin Compose Desktop Text Fields Windows 10

159 views Asked by At

I'm having difficulty getting the soft keyboard to automatically show up in a Kotlin Multiplatform with Compose Desktop app on a Windows 10 device set in tablet mode on a Pipo touch screen computer. I can't tell yet if this is a Windows 10 settings problem or a problem in my development.

Here is one of the TextField components. What's wanted is when the user clicks on it, the keyboard pulls up.

var stationName by remember { mutableStateOf(TextFieldValue("")) } 

TextField(
   label = { Text("Enter Computer Station name") },
   value = stationName,
   singleLine = true,
   onValueChange = { stationName = it }
)

I checked some resources to see if I have the right Windows 10 settings. This includes going to Settings -> Devices -> Typing -> "Automatically show the touch keyboard in windowed apps when there's no keyboard attached to your device" set to Yes.

Any advice to resolve this?

1

There are 1 answers

0
Jesser On BEST ANSWER

What worked is that I used this solution as suggested following the link from @PhilDukhov.

For posterity, in Kotlin it came out to:

// build.gradle.kts

implementation("net.java.dev.jna:5.11.0")
implementation("net.java.dev.jna:jna-platform:5.11.0")

// Keyboard controller

import com.sun.jna.platform.win32.User32
import com.sun.jna.platform.win32.WinDef

fun showKeyboard() {
   val command = "cmd /c \"C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\TabTip.exe\""
   val process = Runtime.getRuntime().exec(command)
   process.waitFor()
   process.destroy()
}

fun hideKeyboard() {
   val keyboardClassName = "IPTIP_Main_Window"
   val wmSysCommand = 0x0112
   val scClose = WinDef.WPARAM(0xF060)
   val handle = User32.INSTANCE.FindWindow(keyboardClassName, "")
   if (handle != null) {
      User32.INSTANCE.SendMessage(handle, wmSysCommand, scClose, WinDef.LPARAM(0))
   }
}