Re: ToAsciiEx/LoadKeyboardLayout question

From: Michael \(michka\) Kaplan [MS] (michkap_at_online.microsoft.com)
Date: 07/31/04


Date: Sat, 31 Jul 2004 02:10:36 -0700


"Alex" <sdfjkhsdkh@ksfjdkjwdfsklj.nowhere> wrote...

> I've encountered somewhat interesting problem in non-english windows.

It seems to me that this problem can just as easily happen by installing any
of the hundreds of possible keyboards on a US English system as running on
non-english Windows....

> The origin of the problem is that keyboard wedge devices send the
> data by emulating "key presses" wisely assuming that the keyboard
> layout is US English. When the current keyboard layout is different,
> it doesn't work so well.

Perhaps the solution is to find "keyboard wedge devices" that do not make
this inappropriate and often incorrect assumption?

> To retrieve these data properly I have to
> pass the input through ToAsciiEx with the HKL from LoadKeyboardLayout
> for US English.

Just curious -- why would you not use ToUnicodeEx here? Since most of those
non-English keyboards will contain entries off of the default system code
page....

> That's fine when the user has US English in the list
> of his inputi methods on his computer. If he doesn't,
> LoadKeyboardLayout adds US English to the list of input methods
> (which probably is not nice to the user).

Yes, this can be confusing. Though I have found (in implementing MSKLC's
"Load From Existing..." functionality) that a "load the layout, get every
piece of info about the layout, unload the layout is a very fast operation.
It works quite well in MSKLC, and it actually handles all of the extreme
cases like SGCAPS and Dead Keys and such....

> If there's nothing I can do
> about it, I would like to remove it from the list at the end of the
> program. I can get layout list before calling LoadKeyboardLayout to
> remember if it was in the user's list or not, but I need to have this
> logic in more than one application which causes even more
> complications.

See above -- its actually very fast. The easiest way to do it:

1) GetKeyboardLayoutList to get the currently loaded list in a nice array
2) LoadKeyboardLayout on your keyboard layout
3) Check to see if the HKL returned by #2 is in the list returned by #1
4) Do whatever you need to do
5) If the answer to #3 is YES then unload the layout when you are done

Like I said, it works quite well, and quite quickly, in MSKLC.

> After studying MSDN help on those functions I can't say I
> understand what they're doing exactly.

Not sure I know what you mean here....

> Interestingly, test
> application doesn't behave the same way on Windows NT and XP. On NT,
> if I unload previously loaded layout, another application that has
> loaded the same layout can keep using it, but on XP it can not.

Well, the cases there have more to do with situations where the unload was
delayed to "on reboot" due to it being in use that were fixed up so that no
wait was required.

> What I'm really looking for is to call ToAsciiEx(...,"eng_US") which
> would be transparent for the user, but I can't find any functions
> which would allow to do it.

There really are none in the Win32 API... though I have yet to ever see the
extra keyboard entry in MSKLC, which follows the steps 1-5 given above. And
it works for any and all keyboard layouts.

> As a last resort, I can hardcode content
> of the US english layout into the application and do translation
> myself, but this method looks somewhat ugly.

Yes. That of course get me back to the original points about the APO choice
and the use of apps that make such a silly mistake about keyboard choices?
:-)

-- 
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies
Windows International Division
This posting is provided "AS IS" with
no warranties, and confers no rights.


Relevant Pages

  • Re: RosAsm?[OT#2]
    ... >> accent marks on some of the word ommitted because of ASCII and UK ... because it has the keyboard layout as a nice little ASCII ... _ONE ADDITION_ that is not on the keyboard diagram but I ... that many UK typists simply "get used" to typing with a UK keyboard ...
    (alt.lang.asm)
  • ToAsciiEx/LoadKeyboardLayout question
    ... I've encountered somewhat interesting problem in non-english windows. ... The origin of the problem is that keyboard wedge devices send the ... layout is US English. ... When the current keyboard layout is different, ...
    (microsoft.public.vc.language)
  • Re: Umlaut
    ... >> an american keyboard, just changing the layout doesn't help. ... >> write in German and my wife occasionaly writes in Spanish. ... English laptop. ...
    (alt.os.linux.suse)
  • Re: ToAsciiEx/LoadKeyboardLayout question
    ... > English system as running on non-english Windows.... ... want to have US English keyboard in his list. ... When the current keyboard layout is ... the user's lists. ...
    (microsoft.public.vc.language)
  • Re: Keyboard registry question
    ... The value is probably there because you have Canadian English for a keyboard ... HKEY_CURRENT_USER\Keyboard Layout ... This subkey ...
    (microsoft.public.windowsxp.setup_deployment)

Loading