import ctypes # Required to obtain the keyboard layout def get_keyboard_language(): """ Gets the keyboard language in use by the current active window process. """ # My keyboard is set to the English - United States keyboard # For debugging Windows error codes in the current thread user32 = ctypes.WinDLL('user32', use_last_error=True) curr_window = user32.GetForegroundWindow() thread_id = user32.GetWindowThreadProcessId(curr_window, 0) # Made up of 0xAAABBBB, AAA = HKL (handle object) & BBBB = language ID klid = user32.GetKeyboardLayout(thread_id) # print(klid) #67699721 # Language ID -> low 10 bits, Sub-language ID -> high 6 bits # Extract language ID from KLID lid = klid & (2**16 - 1) # Convert language ID from decimal to hexadecimal lid_hex = hex(lid) print(lid_hex) #'0x409' - en #'0x419' - ru get_keyboard_language()