Win API for changing input language programmatically

旧时模样 提交于 2021-02-18 11:31:20

问题


I want to change the input language in WinXP to Spanish, programmatically. Is there an API to support that?

Thanks


回答1:


  • LoadKeyboardLayout
  • ActivateKeyboardLayout
  • GetKeyboardLayout

etc.




回答2:


i managed to do it with keyboard events & shortcut assignment.

  1. go to "text services and input language" (that's how it's called windows 7 control panel)
  2. assign keys for the uni-directional language. e.g. "To English", and "To Hebrew". I've chosen Alt-Shift-7 and Alt-Shift-8, because they're rarely used elsewhere.
  3. from your app, send the key combination for the appropriate language, when needed.

Note:

if "your app" is an external utility (I wrote mine in Python), then it must NOT invoke a window, otherwise /your-app/ will steal the focus, and will get the language change. in python I solved it by using a GUI-less pyw script filename. (or invoke the script with pythonw.exe)

this article shows how to send keyboard events in python:

https://python-decompiler.com/article/2012-11/how-to-generate-keyboard-events-in-python



来源:https://stackoverflow.com/questions/819665/win-api-for-changing-input-language-programmatically

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