def autoDetectKeyboardLayout():
    """
    @summary: try to auto detect keyboard layout
    """
    try:
        if os.name == 'posix':    
            from subprocess import check_output
            result = check_output(["setxkbmap", "-print"])
            if 'azerty' in result:
                return "fr"
        elif os.name == 'nt':
            import win32api, win32con, win32process
            from ctypes import windll
            w = windll.user32.GetForegroundWindow() 
            tid = windll.user32.GetWindowThreadProcessId(w, 0) 
            result = windll.user32.GetKeyboardLayout(tid)
            log.info(result)
            if result == 0x40c040c:
                return "fr"
    except Exception as e:
        log.info("failed to auto detect keyboard layout " + str(e))
        pass
    return "en"
def autoDetectKeyboardLayout ( ) : try : if os . name == 'posix' : from subprocess import check_output result = check_output ( [ "setxkbmap" , "-print" ] ) if 'azerty' in result : return "fr" elif os . name == 'nt' : import win32api , win32con , win32process from ctypes import windll w = windll . user32 . GetForegroundWindow ( ) tid = windll . user32 . GetWindowThreadProcessId ( w , 0 ) result = windll . user32 . GetKeyboardLayout ( tid ) log . info ( result ) if result == 0x40c040c : return "fr" except Exception as e : log . info ( "failed to auto detect keyboard layout " + str ( e ) ) pass return "en"
@summary: try to auto detect keyboard layout