My first explanation of klid wasn't correct, but thanks to comments I've corrected that. If you're going to port your code to an OS other than Windows 10 (maybe even earlier versions of Windows, if the LCIDs have changed since then), this approach won't work as expected. Just make sure that you are calling GetKeyboardLayout(thread_id) every time you switch languages on your keyboard.Īs mentioned in the comments, this is system-dependent. If you're interested, here is a plain-text list and here is Microsoft's list of all the hexadecimal values that lid_hex could possibly take on, given an input language.įor your reference, LCIDs are stored in this format (as I described in comments of my code). You can follow the same procedure for Greek ( 0x408), or any other language you'd like to detect. # I switched my keyboard to the Russian keyboard # Convert language ID from decimal to hexadecimal # Language ID -> low 10 bits, Sub-language ID -> high 6 bits > klid = user32.GetKeyboardLayout(thread_id) # Made up of 0xAAABBBB, AAA = HKL (handle object) & BBBB = language ID > thread_id = user32.GetWindowThreadProcessId(curr_window, 0) > curr_window = user32.GetForegroundWindow() > user32 = ctypes.WinDLL('user32', use_last_error=True) create a huge keyboard to map every possible character. # For debugging Windows error codes in the current thread losophy of input method design by seeing it as a non- intrusive plug-in text service framework. # My keyboard is set to the English - United States keyboard The following approach, utilizing the ctypes library, works for me.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |