输入法
April 6, 2024

输入法

April 6, 2024

python中英文输入法切换

April 6, 2024
Python, 输入法

成功环境:win10 64位,搜狗输入法,其他环境未测试 #成功环境:win10 64位,搜狗输入法,其他环境未测试 import win32api, win32con, win32gui,time import ctypes def switch_input_method(): IMC_GETOPENSTATUS = 0x0005 IMC_SETOPENSTATUS = 0x0006 imm32 = ctypes.WinDLL('imm32', use_last_error=True) handle = win32gui.GetForegroundWindow() # 某进程窗口句柄 hIME = imm32.ImmGetDefaultIMEWnd(handle) status = win32api.SendMessage(hIME, win32con.WM_IME_CONTROL, IMC_GETOPENSTATUS, 0) # 返回值 0:英文 1:中文 if status: print('当前中文,切换为英文') win32api.SendMessage(hIME, win32con.WM_IME_CONTROL, IMC_SETOPENSTATUS, 0) # 关 ...


© 2024 Powered By Hugo,模板:Hugo-book . Contact: tndyx@hotmail.com

本站总访问量 本文总阅读量