全部产品
云市场

5.切换输入法

更新时间:2019-09-18 15:36:22

  1. # 设置键盘布局为英文
  2. result = win32api.SendMessage(
  3. hwnd,
  4. WM_INPUTLANGCHANGEREQUEST,
  5. 0,
  6. 0x0409)

Example/实例

Example 切换输入法

  1. from rpa.core import *
  2. from rpa.utils import *
  3. import rpa
  4. from win32con import WM_INPUTLANGCHANGEREQUEST
  5. import win32gui
  6. import win32api
  7. def start():
  8. # 在此处开始编写您的应用
  9. # 语言代码
  10. LID = {0x0804: "Chinese (Simplified) (People's Republic of China)",
  11. 0x0409: 'English (United States)'}
  12. # 获取前景窗口句柄
  13. hwnd = win32gui.GetForegroundWindow()
  14. # 获取前景窗口标题
  15. title = win32gui.GetWindowText(hwnd)
  16. print('当前窗口:' + title)
  17. # 获取键盘布局列表
  18. im_list = win32api.GetKeyboardLayoutList()
  19. im_list = list(map(hex, im_list))
  20. print(im_list)
  21. # 设置键盘布局为英文
  22. result = win32api.SendMessage(
  23. hwnd,
  24. WM_INPUTLANGCHANGEREQUEST,
  25. 0,
  26. 0x0409)
  27. if result == 0:
  28. print('设置英文键盘成功!')
  29. pass