2

Using the tool AutoHotKey I could set Caps Lock key for switching keyboard layouts (here). But I still want to set Caps Lock for Layout_1 and Shift+Caps Lock or backtick ` for Layout_2.

Is it possible to set different combination of keys for different layouts in windows?

Capslock --> 1st Layout

Shift+Caps Lock --> 2nd Layout

mini
  • 81

1 Answers1

1

On my system it's the Alt+Shift combination that changes the keyboard language and this works:

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
}
Relax
  • 3,785