sq.h changes, grabbed reserved field in sqKeyboardEvent
Andreas Raab
andreas.raab at gmx.de
Thu Mar 30 01:58:37 UTC 2006
Hi John -
> So why can't you use ToUnicode() to translate the virtual key code or
> the scan key code into the unicode character?
I wish it were that simple but it wouldn't work - not for the problem
statement that Mike posted (that's why I was asking for it).
The problem statement itself (which is perfectly valid from a user
perspective) is actually remarkably ill-defined from a system
perspective: It asks the key mapper to take three keys as input
(Ctrl-Shift-1) and generate 2 keys output (Ctrl-! or somesuch). The
reason this is ill-defined is that that's not how key mappers work (at
least the one's I know about) - all they care about is the combination
of all keys. Which means that ToUnicode will happily respond to
Ctrl-Shift-1 saying "oh, sorry, there is no Unicode character for that
combination".
And, IIRC (but I need to verify this) ToUnicode is the precise manual
equivalent of what Windows does anyway when it translates WM_KEYDOWN
into WM_CHAR. Which means that all you need is to look at what
characters get generated already to find out how ToUnicode would
respond. Which in the case of our Ctrl-Shift-1 example is not at all (I
tested this with various keyboard layouts which supports the theory).
So for the plain Unicode mapping I can use ToUnicode() - in fact I am
using it already (via WM_KEYDOWN -> WM_CHAR translation) and report it
in the utf32 field for the key stroke event. But I *can't* use
ToUnicode() to solve the problem we were discussing - to map the input
while making arbitrary distinctions between Ctrl and Shift in the
Windows key mapper (not unless we start masking out ctrl state which
immediately leads to other issues - that is exactly what I mean by "it's
a pain").
If you want such a distinction (and that's why the problem statement is
so important) you need to do it manually to begin with. And I'd rather
have that code in the image.
BTW, just out of interest: Does the Mac make a distinction between
certain modifiers when it maps keyboard input? I'd be quite surprised if
you'd get "Ctrl-!" out of mapping Ctrl-Shift-1 as input (but what do I
know ;-)
> Sure I can return 42 the magic number from LMGetKbdType() meaning you
> are using as Estonia keyboard, or maybe
> 78 for Devanagari keyboard in the Indian Language Kit, however it's
> unlikely I or any other developer will want to code the
> keyboard to ascii/macroman/unicode whatever translation tables in the
> image.
That's one good thing about Open Source: It only takes one programmer to
fix that problem and if he's out there the Internet can find him.
Cheers,
- Andreas
More information about the Vm-dev
mailing list