Wie erhalte ich ein Tastaturlayout mit Python auf einem Mac?Python

Python-Programme
Guest
 Wie erhalte ich ein Tastaturlayout mit Python auf einem Mac?

Post by Guest »

Könnten Sie mir bitte sagen, wie ich mit Python das aktuelle Tastaturlayout unter macOS erhalten kann?
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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post