xpra icon
Bug tracker and wiki

Opened 4 years ago

Closed 3 years ago

#1062 closed enhancement (fixed)

better keyboard layout detection on win32

Reported by: Antoine Martin Owned by: Antoine Martin
Priority: critical Milestone: 2.0
Component: platforms Version: trunk
Keywords: win32 Cc:

Description

Sounds like we need GetKeyboardLayoutList and GetLocaleInfo, like Get short windows language name or C++/Win32 Finding all keyboard input languages?.

Found some example code in python kiwi:

import ctypes
def GetLocaleInfo(value):
    s = ctypes.create_string_buffer("\000" * 255)
    ctypes.windll.kernel32.GetLocaleInfoA(0, value, s, 255)
    return str(s.value)

But that doesn't return a value for the layout list items...

It is all a bit confusing: why are the HKL and KLID of the keyboard different?

Here's another method which could be useful for locales:

def get_locale_language():
    #apparently this can be different from the system locale
    try:
        langid = windll.kernel32.GetUserDefaultUILanguage()     #@UndefinedVariable
        import locale
        lang = locale.windows_locale[langid]
        log("default ui language=%s", lang)
        return lang
    except Exception as e:
        log("failed to query current language: %s", e)
        return None

Change History (6)

comment:1 Changed 4 years ago by Antoine Martin

Status: newassigned

Found this useful example: NVDA's languageHandler.py.

And eventually figured out that this gives me what I want:

[locale.windows_locale.get(x & 0xffff) for x  in win32api.GetKeyboardLayoutList()]

(bar any issues with HKL / KLID... as per above)

Which gave me on my test system:

['en_GB', 'en_US', 'fr_FR']

comment:2 Changed 4 years ago by Antoine Martin

See also #1172.

comment:3 Changed 3 years ago by Antoine Martin

Milestone: 1.01.1

Milestone renamed

comment:4 Changed 3 years ago by Antoine Martin

Milestone: 1.12.0

Milestone renamed

comment:5 Changed 3 years ago by Antoine Martin

Priority: majorcritical

Seems to be a problem with the 64-bit builds (#1413)

comment:6 Changed 3 years ago by Antoine Martin

Resolution: fixed
Status: assignedclosed

We have already been using GetKeyboardLayoutList since r13324. (via pywin32)
This was converted to a ctypes implementation in r14690.
See also #1282.
Minor cleanup / x11 py3k fixes in r15086, r15087.

Note: See TracTickets for help on using tickets.