LoadKeyboardLayout does not change the UI of On screen keyboard

耗尽温柔 提交于 2020-01-05 06:52:14

问题


I have activated the Windows On screen keyboard for my application and changed the keyboard layout to Tamil before displaying the onscreen keyboard, using the following code:

Private Const KLF_ACTIVATE As Integer = 1
Dim oskProcess As System.Diagnostics.Process

Private Sub ProdNameText_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProdNameText.GotFocus
        LoadKeyboardLayout("00000449", KLF_ACTIVATE)
        oskProcess = Process.Start("osk.exe") 
End Sub

I am able to type in Tamil into the text box by:

  • Pressing keys in my keyboard
  • Clicking the keys in the onscreen keyboard

But the onscreen keyboard displays the characters in English only. When I click the Tamil Language in the language bar, the keys in the onscreen keyboard shows Tamil characters.

Why the characters of the onscreen keyboard does not change according to the change in the current keyboard layout, when the change is done programmatically?


回答1:


That's because the keyboard layout is a per-process property. You only changed the keyboard layout for your process, not for osk.exe.

There is no winapi function to change the keyboard layout for another process. Given that the language bar knows how to do it only provides a hint that it is possible but it is a pretty well kept secret. The language bar is controlled through the Text Services Framework api (ItfLangBarMgr et al), a quite unpleasant api and quite difficult to use from managed code. A quick glance shows no interface method that obviously supports changing a layout. Probably the best hint that this is difficult/impossible is that osk.exe doesn't do this, a feature you'd expect it to have. I'd have to recommend you stick with the language bar.



来源:https://stackoverflow.com/questions/14534700/loadkeyboardlayout-does-not-change-the-ui-of-on-screen-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!