世界线变动率搜索中...
831 字
4 分钟
Using AutoHotkey to Quickly Switch Between Multiple Input Languages
2026-01-21
统计加载中...

提示: 本文英文译文由 LLM(大语言模型)辅助翻译,可能存在不准确之处,请以中文原文为准。
Note: The English translation in this post was assisted by an LLM and may contain inaccuracies. Please refer to the original Chinese text for the most accurate meaning.
Chinese original: Read in Chinese


Why Abandon Windows’ Native Switching?#

Windows’ default input language switching hotkeys become painfully inefficient once you have more than two languages. I regularly type in three languages, and using the default shortcut to cycle through them was frustrating. So I used AutoHotkey to repurpose a few spare keys on my keyboard to switch directly to a specific input language/keyboard layout. This turns sequential (cycling) switching into deterministic switching: press one key and land on the language you want.

My Personal Solution#

My keyboard is a 108-key model with four built-in multimedia keys. I rarely use these keys, so I chose them as my language switching keys. With AutoHotkey, I mapped each key to switch directly to a specific input language/keyboard layout.

My mappings are as follows:

KeySwitch to
MuteEnglish Input
Volume -Chinese Input
Volume +Japanese Input

Implementation Logic#

I use the PostMessage function to send a system input-language change request to the active window. The target language’s LCID is included in the parameters, which is what makes the switch deterministic.

The specific code is as follows:

#Requires AutoHotkey v2.0
; Force only one script instance to run.
; If the script is already running, launching it again will automatically replace the old instance.
; This is convenient when you tweak the script and want the changes to take effect immediately.
#SingleInstance Force
; --- Key Mapping Section ---
; Logic: Intercept media keys -> Call switch function -> Pass the corresponding language ID (LCID)
; Note: The original media functions of these keys (mute / volume control) will be completely overridden.
Volume_Mute::SwitchToLang(0x0409) ; 0x0409 = English (United States)
Volume_Down::SwitchToLang(0x0804) ; 0x0804 = Chinese (Mainland China)
Volume_Up::SwitchToLang(0x0411) ; 0x0411 = Japanese
; --- Core Function ---
SwitchToLang(LangID) {
; PostMessage: Places a message into the target window's message queue (returns immediately, fast)
; Parameter details:
; 1. 0x50 : Message code WM_INPUTLANGCHANGEREQUEST (request an input language change)
; 2. 0 : wParam (system flag). 0 means "use default behavior"
; 3. LangID : lParam (language identifier), e.g., 0x0409 passed in above
; 4. (empty): Control (control name). Left empty since we send to the whole window
; 5. "A" : The currently active window
PostMessage(0x50, 0, LangID,, "A")
}

Common LCID Reference#

You can replace the LCIDs according to your needs.

Language/LayoutLCID
Chinese (Simplified)0x0804
English (United States)0x0409
Japanese0x0411
Korean0x0412
Chinese (Traditional - Taiwan)0x0404
Chinese (Traditional - Hong Kong)0x0C04

Scope of Application & Limitations#

This method switches the input language / keyboard layout. It works best when each language maps to a single input method:

  • ✅ Suitable: One language → one IME/layout (e.g., Chinese only uses Microsoft Pinyin, Japanese only uses Microsoft Japanese, English only uses the US keyboard)
  • ❌ Not ideal: One language → multiple IMEs (e.g., Chinese has both Rime and Microsoft Pinyin). If you want to switch to a specific IME within the same language, this approach is usually not enough.

In the second case, you typically need to use HKL to target a specific input method. I haven’t needed that, so I won’t expand on it here.

How to Find Key Names to Customize Your Mappings?#

Use AutoHotkey’s built-in Key History and Script Info window.

  1. First run the script above (or any AutoHotkey script)
  2. Find the AutoHotkey icon in the taskbar
  3. Right-click and select Open or Help (may vary by version)
  4. In the window that opens, click View at the top
  5. Select Key history and script info
  6. Press the key you want to bind, then refresh the page (default: F5). You’ll see the corresponding name in the log.

Once you know the key name, you can modify the code above (like this):

YourKeyName::SwitchToLang(0x0409)

How to Set Up Auto-Start on Boot?#

There are two methods below: placing it in the Startup folder, or using Task Scheduler.

Method 1: Place in the Startup Folder#

  1. Press Win + R
  2. Enter shell:startup
  3. Drop a shortcut to your .ahk script into that folder

This method is very simple. However, in some apps/windows, administrator privileges may be required for the script to work.

Method 2: Task Scheduler#

If you find that some apps/windows can’t use this script, you may need to run the AutoHotkey script with administrator privileges.

General approach:

  1. Use Windows search to find Task Scheduler, then open it
  2. Select Create Task (not Create Basic Task)
  3. Name it whatever you want
  4. In the General tab → Security options, check Run only when user is logged on, and check Run with highest privileges
  5. Switch to the Actions tab, click New, and set the program/script to your .ahk file path

Pro tip: There’s a Hidden option in the General tab. If you check it, Task Scheduler will start the task without popping up a UAC confirmation window.

Potential Risks#

Tools like AutoHotkey may be flagged as cheating tools by anti-cheat systems in certain games. If your game uses aggressive anti-cheat, it’s safer not to use AutoHotkey scripts—or exit AutoHotkey while playing.

Using AutoHotkey to Quickly Switch Between Multiple Input Languages
/posts/20260121_using-autohotkey-to-quickly-switch-between-multiple-input-languages/
作者
東山
发布于
2026-01-21
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

Profile Image of the Author
東山
Ciallo~(∠・ω< )⌒★

统计加载中...
实验室员布告
欢迎光临第八曜观测站。此处皆为東山的个人碎碎念,主观且片面。若有不同见解,请以您的观点为准 —— 您是对的。