python怎么转化输入法[python高级教程]
python转化输入法的方法:
# 设置键盘布局
set keyboard layout
# 语言代码
from win32con import WM_INPUTLANGCHANGEREQUESTimport win32gui
import win32api
# https://msdn.microsoft.com/en-us/library/cc233982.aspx
LID = {0x0804: "Chinese (Simplified) (People's Republic of China)",
0x0409: 'English (United States)'}
# 获取前景窗口句柄
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)
if result == 0:
print('设置英文键盘成功!')
以上是 python怎么转化输入法[python高级教程] 的全部内容, 来源链接: utcz.com/z/540502.html