Skip to content

Windows 自動切換輸入法程式 Chinese computer user always annoyed with modifying input types between Chinese and English every now and then. Sometimes you type in a lot of words but finally find it was under wrong input type. It is a kind of tolerant. So I write this tiny Python code to solve this problem. With this program, we almost no need to press "Shi…

Notifications You must be signed in to change notification settings

voidism/Input_Method_auto-Modifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modify Input Type Automatically 自動切換輸入法程式

Mon, Jul 31, 2017 5:48 PM

程式效果

  • 使用英文輸入法鍵入兩個中文字之按鍵組合時,會自動切換成中文輸入法,並幫你刪錯字再重新輸入原本想打的字
  • 英文效果亦同,但為避免誤換輸入法,只有在輸入字庫中的單字時,才會轉換成英文輸入法,字庫會自動新增單字 (詳見 關於字庫 )
  • 應該有比微軟內建自動切換好用87倍

GIF

環境需求(Windows)

  • Python2.7
  • PyHook (下載 pyHook‑1.5.1‑cp27‑cp27m‑win32.whl [#如果你python裝的是64bit,可以載amd64的] 然後在檔案目錄pip install pyHook‑1.5.1‑cp27‑cp27m‑win32.whl)
  • pythoncom (附在pypiwin32裡面) (下載 pypiwin32-219-cp27-none-win32.whl [#如果你python裝的是64bit,可以載amd64的] 然後在檔案目錄pip install pypiwin32-219-cp27-none-win32.whl)
  • PyUserInput (下載 PyUserInput-0.1.11-py2-none-any.whl ,然後pip install PyUserInput-0.1.11-py2-none-any.whl)
  • PyAutoGUI (有內建,直接pip install pyautogui就好)

※ 以上建議在虛擬環境中裝設,會比較乾淨

前置作業

由於微軟新注音輸入法不是什麼開源的軟體,一般情況下程式沒有方法可以取得當前的輸入法,所以要用PyAutoGUI來偷吃步:

  1. 找到工具列右下角顯示中英文輸入法的地方
  2. 找到一個像素位置,當中文輸入時是白色,英文輸入時是黑色(黑色的RGB值須分別皆大於200) p.s. 我是選英字撇捺中間的地方

  1. Hook.py來查看該像素格的座標位置 (Hook.py需在環境建置好之後才能用)

Hook.py會不斷更新顯示滑鼠游標的座標位置及RGB值:

--- Position: (1361, 1002) #-->座標位置 RGB: (270, 270, 270) #-->RGB值 --- 
  1. ModifyInputType.py程式碼126行的pixel=(1683, 1063)改成你自己取得的pixel位置
  2. If it's stupid but it works, it isn't stupid.

啟動

就直接執行 ModifyInputType.py

如果有使用virtualenv,可以寫一個bat檔,像這樣:

@echo off cmd /k "cd /d C:\path\to\your\virtualenv_location\Scripts & activate & cd /d C:\path\to\to\your\file & python ModifyInputType.py" 

之後就不用先開虛擬環境再執行囉,可以直接執行或是設定排程。

結束

直接關閉視窗 或是輸入enter, z, x, c, v 跳出程序回到cmd

關於字庫

  • 取用自Mac及Linux的內建字庫,原有45000餘字,刪去"so", "up", "go"...等會與中文輸入混淆的字( so: "ㄋㄟ", up: "ㄧㄣ", go: "ㄕㄟ"...)
  • 當使用者使用中文輸入法打進一串英文字,但因英文字並不在字庫裡,所以沒有自動切換輸入法時,使用者通常會手動按shift切輸入法,這時剛剛所打的那串英文字會自動新增到字庫裡。因此使用者可藉此新增單字
  • 另外可藉由Dictionary_Add&Del.py的GUI介面來找查或新增刪除字庫內的字

About

Windows 自動切換輸入法程式 Chinese computer user always annoyed with modifying input types between Chinese and English every now and then. Sometimes you type in a lot of words but finally find it was under wrong input type. It is a kind of tolerant. So I write this tiny Python code to solve this problem. With this program, we almost no need to press "Shi…

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published