python代碼如何實現(xiàn)切換中英文輸入法
更新時間:2023年11月08日 08:37:51 作者:飛翔的宮保雞丁
這篇文章主要介紹了python代碼如何實現(xiàn)切換中英文輸入法,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
python代碼切換中英文輸入法
代碼實現(xiàn)切換中英文輸入法
from win32con import WM_INPUTLANGCHANGEREQUEST
import win32gui
import win32api
def set_english_inputer():
# 0x0409為英文輸入法的lid_hex的 中文一般為0x0804
hwnd = win32gui.GetForegroundWindow()
title = win32gui.GetWindowText(hwnd)
im_list = win32api.GetKeyboardLayoutList()
im_list = list(map(hex, im_list))
result = win32api.SendMessage(hwnd, WM_INPUTLANGCHANGEREQUEST, 0, 0x0409)
if result == 0:
print("英文輸入法切換成功!")python萬能切換輸入法英文狀態(tài)
# 轉(zhuǎn)換為英文狀態(tài)
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() # 讀取剪貼板的數(shù)據(jù)
clipboard = GetClipboardData(CF_UNICODETEXT)
CloseClipboard() #關(guān)閉
pyautogui.press('backspace')
text=clipboard
if '·' in text and '!'in text and '¥'in text and '%'in text and '……'in text:
print('當(dāng)前輸入法為中文狀態(tài)')
pyautogui.press('shift') # 切換英文狀態(tài)
print('已切換英文狀態(tài)')
# 關(guān)閉搜索框
subprocess.run('taskkill /F /IM SearchUI.exe', shell=True)
return '中文'
print('當(dāng)前輸入法為英文狀態(tài)')
# 關(guān)閉搜索框
subprocess.run('taskkill /F /IM SearchUI.exe', shell=True)
return '英文'
eng_chin()系統(tǒng) 默認輸入法,搜狗不能成功
# 指定系統(tǒng)默認輸入法,切換中文狀態(tài)
def input_fa():
import uiautomation as uia
import pyautogui
win = uia.PaneControl(ClassName="Shell_TrayWnd",Name="任務(wù)欄")
retext=win.ButtonControl(ClassName="IMEModeButton").Name
print(retext)
if '中文' in retext.replace('\n',''):
pyautogui.press('shift') #切換狀態(tài)
return retext
input_fa()總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
pycharm中django框架連接mysql數(shù)據(jù)庫的方法
這篇文章主要介紹了pycharm中django框架連接mysql數(shù)據(jù)庫的方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-04-04
Python實現(xiàn)多圖繪制系統(tǒng)的示例代碼
這篇文章主要為大家詳細介紹了Python如何實現(xiàn)制作一個多圖繪制系統(tǒng),文中的示例代碼簡潔易懂,具有一定的借鑒價值,感興趣的小伙伴可以學(xué)習(xí)一下2023-09-09
安裝python-docx后,無法在pycharm中導(dǎo)入的解決方案
這篇文章主要介紹了安裝python-docx后,無法在pycharm中導(dǎo)入的解決方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03
這篇文章主要為大家介紹了python中selenium模塊的安裝和配置環(huán)境變量教程、提取數(shù)據(jù)操作、無頭模式,有需要的朋友可以借鑒參考下,希望能夠?qū)Υ蠹矣兴鶐椭?/div> 2022-10-10
使用Python模塊進行數(shù)據(jù)處理的詳細步驟
Python 提供了豐富的模塊和庫,用于處理各種類型的數(shù)據(jù),本文介紹了一些常用的模塊和庫,以及如何使用它們進行數(shù)據(jù)處理的詳細步驟和代碼示例,對我們的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2025-02-02最新評論

