#206 keyboard-input charset not initialized correctly on Win32

Petr Pajas

Problem from users' perspective: Windows users of my
Tk-based app who
have Czech keyboard (CS) set as *default* couldn't
Czech characters into input entries until they switch
from CS->EN->CS using the Alt+Shift
Windows shortcut (until they do, messy characters
appear on the screen instead). After the switching to
EN and back everything worked fine (it also works
fine if EN keyboard layout is the default and the
user switches to CZ after the app starts).

Going through the win32 sources, I identified the
problem win/tkWinX.c. The best patch I could manage
is attached.

Here's what happens: tkWinX tracks keyboard layout
switches by listening to the Win32
WM_INPUTLANGCHANGE event in order to keep its info
about the current input encoding up-to-date. The
problem is, that it doesn't initialize its internal
variables according to the initial layout at
aplication startup (probably
assuming its always EN).

The patch adds a short code to TkWinXInit that uses
GetKeyboardLayout winapi call to determine current
keyboard layout, then translates this information
into charset code which it uses to update the Tk's
variables in the exact same way as WM_INPUTLANGCHANGE
event does.

Please have a look at the patch and consider applying
it. The diff is taken against CVS head.


  • Donal K. Fellows

    • labels: --> 68. Win Window Operations
    • priority: 5 --> 8
    • assigned_to: nobody --> hobbs
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2005-12-06

    Logged In: YES

    This just missed the 8.4.12 release ... in any case, there
    is no patch attached???

  • Petr Pajas

    Petr Pajas - 2005-12-06

    Logged In: YES

    Hm, I probably forgot to check the checkbox beside "Attach
    a File" when creating the report, sorry about that. Hope
    this time the patch gets there.

  • Petr Pajas

    Petr Pajas - 2005-12-06


  • Jeffrey Hobbs

    Jeffrey Hobbs - 2006-03-31
    • status: open --> closed-fixed
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2006-03-31

    Logged In: YES

    The patch seemed odd - proper ini in TkWinXInit is now set as:

    if (GetLocaleInfo(LANGIDFROMLCID(GetKeyboardLayout(0)),
    (LPTSTR) &lpCP, sizeof(lpCP)/sizeof(TCHAR))
    && TranslateCharsetInfo((DWORD *)lpCP, &lpCs,

    added to 8.4.13 and 8.5 head as soon as SF cvs returns.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks