当前位置:   article > 正文

python万能切换输入法英文状态_python 设置输入法为英文

python 设置输入法为英文
# 转换为英文状态
def eng_chin():
    import pyautogui
    from win32clipboard import GetClipboardData, OpenClipboard, CloseClipboard
    from win32con import CF_TEXT
    from win32con import CF_UNICODETEXT
    import subprocess
    # 打开搜索框
    subprocess.run('start ms-settings:search', shell=True)
    # subprocess.Popen(['explorer', 'shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}'])
    pyautogui.press('`')
    pyautogui.hotkey('shift','1')
    pyautogui.hotkey('shift','4')
    pyautogui.hotkey('shift','5')
    pyautogui.hotkey('shift','6')
    pyautogui.hotkey('ctrl','a')
    pyautogui.hotkey('ctrl','c')
    OpenClipboard()  # 读取剪贴板的数据
    clipboard = GetClipboardData(CF_UNICODETEXT)
    CloseClipboard() #关闭
    pyautogui.press('backspace')
    text=clipboard
    if '·' in text and '!'in text and '¥'in text and '%'in text and '……'in text:
        print('当前输入法为中文状态')
        pyautogui.press('shift')  # 切换英文状态
        print('已切换英文状态')
        # 关闭搜索框
        subprocess.run('taskkill /F /IM SearchUI.exe', shell=True)
        return '中文'
    print('当前输入法为英文状态')
    # 关闭搜索框
    subprocess.run('taskkill /F /IM SearchUI.exe', shell=True)
    return  '英文'

eng_chin()


系统 默认输入法,搜狗不能成功

# 指定系统默认输入法,切换中文状态
def input_fa():
    import uiautomation as uia
    import pyautogui
    win = uia.PaneControl(ClassName="Shell_TrayWnd",Name="任务栏")
    retext=win.ButtonControl(ClassName="IMEModeButton").Name
    print(retext)
    if '中文' in retext.replace('\n',''):
        pyautogui.press('shift') #切换状态
    return retext
input_fa()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/601047
推荐阅读
相关标签
  

闽ICP备14008679号