问题
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.
- go to "text services and input language" (that's how it's called windows 7 control panel)
- 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.
- 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