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
}