python 怎么转化输入法

python转化输入法的方法:

# 设置键盘布局

setkeyboardlayout

# 语言代码

fromwin32conimportWM_INPUTLANGCHANGEREQUEST
importwin32gui
importwin32api
#https://msdn.microsoft.com/en-us/library/cc233982.aspx
LID={0x0804:"Chinese(Simplified)(People'sRepublicofChina)",
0x0409:'English(UnitedStates)'}

# 获取前景窗口句柄

hwnd=win32gui.GetForegroundWindow()

# 获取前景窗口标题

title=win32gui.GetWindowText(hwnd)
print('当前窗口:'+title)

# 获取键盘布局列表

im_list=win32api.GetKeyboardLayoutList()
im_list=list(map(hex,im_list))
print(im_list)

# 设置键盘布局为英文

result=win32api.SendMessage(
hwnd,
WM_INPUTLANGCHANGEREQUEST,
0,0x0409)
ifresult==0:
print('设置英文键盘成功!')