#1 2024-09-24 16:37:01

Serebro
Reputation: +1067
Location: Moldova
Registered: 2014-03-28
Posts: 2,671
Windows 10 Chrome 129.0

Changing Keyboard Layout on Win 11

As you know, it's impossible to change the keyboard layout on windows 11 the regular way.

This is a workaround how to do it.

1) Install AutoHotkey 2.0 software (it's free).
2) Create a new empty script file in it. It should be in .ahk format by default. Put it on desktop.
3) Open it with a text editor, such as notepad++ and put my code and save it.
4) Right click the script on destop and Run as Administrator.
5) Test by pressing Alt+Shift buttons in game, layout should change.

** If you are scared of code you can download my script, instead of creating a new one smile
https://drive.google.com/file/d/1z-q9nh … sp=sharing

The code:

#Requires AutoHotkey 2.0
#SingleInstance

; Variable to track the last time the keyboard layout was changed
LastChangeTime := 0

; Function for switching keyboard layout
SwitchKeyboardLayout() {
    global LastChangeTime ; Use the global variable
    CurrentTime := A_TickCount ; Get current time in milliseconds

    ; Check if it has been less than 1000 milliseconds since the last change
    if (CurrentTime - LastChangeTime < 1000) {
        return ; Exit if last change was less than 1 second ago
    }

    ; Update the last change time
    LastChangeTime := CurrentTime

    ; Get the active window
    hwnd := WinGetID("A") ; Get the ID of the active window
    if hwnd {
        ; Switch keyboard layout for the active window
        PostMessage(0x50, 0, 0, , hwnd)
    } else {
        MsgBox("Active window not found!")
    }
}

; Set a timer to check for Alt + Shift key combination
SetTimer(CheckAltShift, 10)

CheckAltShift() {
    static altShiftPressed := false

    ; Check if both Alt and Shift are pressed
    if GetKeyState("LAlt", "P") && GetKeyState("LShift", "P") {
        if !altShiftPressed {
            altShiftPressed := true ; Mark as pressed
            SwitchKeyboardLayout() ; Change keyboard layout
        }
    } else {
        if altShiftPressed {
            altShiftPressed := false ; Reset the flag when released
        }
    }
}

Last edited by Serebro (2024-09-24 17:13:28)

Offline

    Positive reputation 2   Negative reputation 0

Board footer