赞
踩
# 转换为英文状态 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()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。