Replies: 2 comments 1 reply
-
I can provide an example like: code: @file:JvmName("WindowsImm32Util")
import com.sun.jna.Library
import com.sun.jna.Native
import com.sun.jna.platform.win32.User32
import com.sun.jna.platform.win32.WinDef
import com.sun.jna.platform.win32.WinNT
/**
* @author lhDream
* @Date 2022-7-30 15:53:44
*/
class WindowsImm32Util {
interface Imm32 :Library{
fun ImmGetContext(hwnd: WinDef.HWND): WinNT.HANDLE?
fun ImmAssociateContext(hwnd: WinDef.HWND, himc: WinNT.HANDLE?): WinNT.HANDLE?
fun ImmReleaseContext(hwnd: WinDef.HWND, himc: WinNT.HANDLE): Boolean
fun ImmCreateContext(): WinNT.HANDLE?
fun ImmDestroyContext(himc: WinNT.HANDLE): Boolean
}
companion object{
private var imm32: Imm32? = null
private val user32 = User32.INSTANCE
private var status = true
init {
imm32 = Native.load("imm32",Imm32::class.java)
}
/**
* 打开输入法
*/
@JvmStatic
fun open() {
if (status) {
return
}
status = true
val hwnd = user32.GetForegroundWindow()
var himc = imm32?.ImmGetContext(hwnd)
himc?.let { himc = imm32?.ImmCreateContext() }
himc?.let {
imm32?.ImmAssociateContext(hwnd, it)
imm32?.ImmReleaseContext(hwnd, it)
}
}
/**
* 关闭输入法
*/
@JvmStatic
internal fun close() {
if (!status) {
return
}
status = false
val hwnd = user32.GetForegroundWindow()
val himc = imm32?.ImmAssociateContext(hwnd, null)
if (himc != null) {
imm32?.ImmDestroyContext(himc)
}
himc?.let { imm32?.ImmReleaseContext(hwnd, it) }
}
}
} pom.xml <dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.2.0</version>
</dependency> |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for this and the example, but you're right, the code in FXGL tries to be cross-platform as much as possible. The only native code present at the moment is for xbox/ps controllers but it is also written in a cross-platform way via SDL. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi @AlmasB !
Are you consider add functions related to resolving input method conflicts? This may be strongly platform-dependent。
Beta Was this translation helpful? Give feedback.
All reactions