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

  • 1
    You can write two batch scripts that select one of the two layouts (instructions and example and attach each of those scripts tot a key using AutoHotKey. – agtoever Mar 16 at 8:12
  • simple solution is to set some combo e.g. Alt+Shift+1 via keyboard setup first and then bind it with Autohotkey to Capslock – Mikhail V Mar 16 at 11:53
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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.