Ich habe diesen Code, der unter Windows und Linux funktioniert, aber unter Windows funktioniert er offensichtlich nicht macOS.
Code: Select all
def get_current_keyboard_layout_linux():
try:
keyboard = XKeyboard()
layout = keyboard.group_name
return layout
except Exception as e:
print("Error getting keyboard layout:", e)
return None
Code: Select all
def get_current_keyboard_layout_windows():
hwnd = ctypes.windll.user32.GetForegroundWindow()
thread_id = ctypes.windll.user32.GetWindowThreadProcessId(hwnd, 0)
klid = ctypes.windll.user32.GetKeyboardLayout(thread_id)
return klid & 0xFFFF