设置不同的按键来切换不同的键盘布局,在Windows下如何实现?

设置不同的按键来切换不同的键盘布局,在Windows下如何实现?

使用工具 AutoHotKey 我可以设置Caps Lock用于切换键盘布局的键(这里)。但是我仍然想Caps Lock为 Layout_1 设置,并为 Layout_2 设置Shift+Caps Lock或反引号。`

是否可以为窗口中的不同布局设置不同的组合键?

Capslock--> 第一个布局

Shift+ Caps Lock--> 第二个布局

答案1

在我的系统上,Alt+Shift 组合键更改键盘语言并且这有效:

SetCapsLockState, AlwaysOff ; Forces the CapsLock key to stay off permanently

; Replace 0x0409 and 0x1407 with the Language identifier of your keyboard languages described here:
; https://docs.microsoft.com/en-us/windows/desktop/intl/language-identifier-constants-and-strings

Capslock:: ; 1st Layout
If !(GetKeyboardLanguage(WinActive("A")) = 0x0409) ; English ; "!" means "NOT"
    SendInput, {Alt Down}{Shift Down}{Shift Up}{Alt Up}
return

+CapsLock:: ; 2nd Layout
If !(GetKeyboardLanguage(WinActive("A")) = 0x1407) ; German
    SendInput, {Alt Down}{Shift Down}{Shift Up}{Alt Up}
return

; https://autohotkey.com/board/topic/116538-detect-which-language-is-currently-on/#entry672236   
GetKeyboardLanguage(_hWnd=0){
    if !_hWnd
        ThreadId=0
    else
        if !ThreadId := DllCall("user32.dll\GetWindowThreadProcessId", "Ptr", _hWnd, "UInt", 0, "UInt")
            return false    
    if !KBLayout := DllCall("user32.dll\GetKeyboardLayout", "UInt", ThreadId, "UInt")
        return false    
    return KBLayout & 0xFFFF
}

相关内容