亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python代碼如何實(shí)現(xiàn)切換中英文輸入法

 更新時(shí)間:2023年11月08日 08:37:51   作者:飛翔的宮保雞丁  
這篇文章主要介紹了python代碼如何實(shí)現(xiàn)切換中英文輸入法,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

python代碼切換中英文輸入法

代碼實(shí)現(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) 默認(rèn)輸入法,搜狗不能成功

# 指定系統(tǒng)默認(rèn)輸入法,切換中文狀態(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é)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論