“要实现中英文切换,首先你得Windows系统必须要有中文语言对应的输入法和英文语言对应的输入法,简单说就是要有中文语言和英文语言,才能实现输入法(语言)切换。”
import win32api
import win32gui
from win32con import WM_INPUTLANGCHANGEREQUEST
def change_language(lang="EN"):
""" 切换语言 :param lang: EN––English; ZH––Chinese :return: bool """
LANG={
"ZH":0x0804,
"EN":0x0409
}
hwnd=win32gui.GetForegroundWindow()
language=LANG[lang]
result=win32api.SendMessage(
hwnd,
WM_INPUTLANGCHANGEREQUEST,
0,
language
)
if not result:
return True