在 Pipo 触摸屏计算机上设置为平板电脑模式的 Windows 10 设备上,我很难让软键盘自动显示在带有 Compose Desktop 应用程序的 Kotlin 多平台中。我还无法判断这是 Windows 10 设置问题还是我的开发问题。
这是
TextField
组件之一。想要的是当用户单击它时,键盘会拉起。
var stationName by remember { mutableStateOf(TextFieldValue("")) }
TextField(
label = { Text("Enter Computer Station name") },
value = stationName,
singleLine = true,
onValueChange = { stationName = it }
)
我检查了一些资源,看看我的 Windows 10 设置是否正确。这包括转到“设置”->“设备”->“打字”->“当设备没有连接键盘时自动在窗口应用程序中显示触摸键盘”设置为“是”。
有什么建议可以解决这个问题吗?
有效的是我按照@PhilDukhov 的链接的建议使用了这个解决方案。
对于子孙后代来说,Kotlin 的结果是:
// 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))
}
}