Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better keyboard layout detection on win32 #1062

Closed
totaam opened this issue Dec 23, 2015 · 10 comments
Closed

better keyboard layout detection on win32 #1062

totaam opened this issue Dec 23, 2015 · 10 comments

Comments

@totaam
Copy link
Collaborator

totaam commented Dec 23, 2015

Issue migrated from trac ticket # 1062

component: platforms | priority: critical | resolution: fixed | keywords: win32

2015-12-23 12:56:10: antoine created the issue


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
@totaam
Copy link
Collaborator Author

totaam commented Dec 23, 2015

2015-12-23 13:22:51: antoine changed status from new to assigned

@totaam
Copy link
Collaborator Author

totaam commented Dec 23, 2015

2015-12-23 13:22:51: antoine commented


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']

@totaam
Copy link
Collaborator Author

totaam commented Apr 17, 2016

2016-04-17 03:58:40: antoine commented


See also #1172.

@totaam
Copy link
Collaborator Author

totaam commented Jul 12, 2016

2016-07-12 17:51:51: antoine commented


Milestone renamed

@totaam
Copy link
Collaborator Author

totaam commented Aug 21, 2016

2016-08-21 10:55:50: antoine commented


Milestone renamed

@totaam
Copy link
Collaborator Author

totaam commented Jan 23, 2017

2017-01-23 09:27:48: antoine changed priority from major to critical

@totaam
Copy link
Collaborator Author

totaam commented Jan 23, 2017

2017-01-23 09:27:48: antoine commented


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

@totaam
Copy link
Collaborator Author

totaam commented Feb 16, 2017

2017-02-16 05:40:44: antoine changed status from assigned to closed

@totaam
Copy link
Collaborator Author

totaam commented Feb 16, 2017

2017-02-16 05:40:44: antoine set resolution to fixed

@totaam
Copy link
Collaborator Author

totaam commented Feb 16, 2017

2017-02-16 05:40:44: antoine commented


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant