python获取windows当前的输入法是中文还是英文

import ctypes
import time
import os

print('5秒后本程序会开始运行,\n请迅速将本程序置于后台,\n然后到文本编辑器之类的软件的输入框切换输入法到需要的状态\n\n')
time.sleep(5)

user32 = ctypes.WinDLL('user32', use_last_error=True)
curr_window = user32.GetForegroundWindow()
thread_id = user32.GetWindowThreadProcessId(curr_window, 0)
klid = user32.GetKeyboardLayout(thread_id)
lid = klid & (2**16 - 1)
lid_hex = hex(lid)

print(lid_hex)
if lid_hex == '0x409':
    print('当前的输入法状态是英文输入模式\n\n')
elif lid_hex == '0x804':
    print('当前的输入法是中文输入模式\n\n')
else:
    print('当前的输入法既不是英文输入也不是中文输入\n\n')

input('请按回车键结束')

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值