Keyboard layout change is not detected
BoannWasHere opened this issue · 0 comments
This is an unusual case, I appreciate.
I'm trying to make a typing assist program as I get hand pains. I also use both Dvorak and Qwerty in different applications. This is on Linux with KDE Plasma (X11), where I have the KDE keyboard layout "Switching Policy" set to "Application".
When I start JNativeHook it correctly detects the current keyboard layout initially, but when I switch to a different application I get gibberish text, because it's continuing to interpret it as Dvorak when it should be Qwerty, or vice-versa.
As a workaround I added a manual hotkey, which tries to redetect the layout by calling:
GlobalScreen.unregisterNativeHook();
GlobalScreen.registerNativeHook();
But calling registerNativeHook the second time does nothing, so JNativeHook just stops.
So the only way I can adapt to keyboard layout changes is to restart the JVM, and make sure that the intended application is focused at the time it starts. It's not ideal.
I don't know if there's an easy way to fix this, but thanks for all that you do.