Using multiple keyboards

by Michael S. Kaplan, published on 2005/11/17 04:01 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2005/11/17/492328.aspx


The other day, Jerry Pisk asked in the Suggestion Box:

How does Windows handle input from multiple keyboards? Can each keyboard have a different layout? Do dead and control (shift/control/alt/win/context) keys cross keyboards and what happens if each is set to a different layout? How about the lock keys (caps/num/scroll)?

To Windows, each thread has an input method (it might be a selected keyboard layout or whatever).

Whether there is one keyboard or many keyboards, than each of those keyboards has a bunch of keys on it and each key has a scan code. It is the keyboard layout that takes those scan codes and maps them to virtual keys and sometimes even characters. But it does not pay attention to which hardware keyboard you type on (you can even split typing between them, mixing the typing of dead keys between them).

So the answer to your question would be that each thread can have a different layout but the keyboards themselves are all shared for the system when they are typed in.

Now application developers can take advantage of Raw Input between the various Human Interface Devices such as keyboards, joysticks, mice, microphones, and so on. You could even theoretically use this information to distinguish between keyboards and then use the traditional Keyboard Input API functions to map each keyboard to a different layout. But that would be a lot of work to do, especially in cases where you would have to keep your own buffer for the input of dead keys and such.

It is much more reasonable to stick with the built-in model, in my opinion. :-)

 

This post brought to you by "ʢ" (U+02a2, LATIN LETTER REVERSED GLOTTAL STOP WITH STROKE)


# Rosyna on 17 Nov 2005 7:34 AM:

Funny that you post about this now. I'm in Japan for the next two months and decided to get a Japanese keyboard to test with. This thing is weird. It's got extra keys that I have *no* idea what they do and all the normal keys are all moved around (It is still qwerty though) so I have to retrain some of my muscle memory. Argh¥¥¥.

# Jerry Pisk on 17 Nov 2005 2:19 PM:

So it is entirely valid to receive two WM_KEYDOWN for the same key before receiving WM_KEYUP twice, right? I press A on one keyboard and press it again on the other before I release them both. Wonder how many programs that handle DOWN/UP messages test for this :)

# Gabe on 18 Nov 2005 4:48 AM:

I would expect a separate WM_KEYDOWN for each time a key repeats, with the WM_KEYUP usually thrown away or doing something idempotent. It's unlikely you would find a program that handles multiple WM_KEYUP messages in an unexpected way.

BTW, since you mentioned RawInput, do you know of any place that has documentation on how to actually decode HID input? How about for devices other than keyboards and mice?

# Michael S. Kaplan on 18 Nov 2005 6:10 AM:

Hi Gabe --

It is funny -- the docs tell you to not expect th ecount of WM_KEYDOWN and WM_KEYUP messages to match -- the multgiple keyboard scenario is just one of the many reasons. :-)

I do not know of a whole lot documentation for the raw input functions -- it is an area that I would love to see more info/samples on, myself....

# Jerry Pisk on 18 Nov 2005 3:09 PM:

Let me turn it around - it's possible to get two WM_KEYUP without WM_KEYDOWN between them.

# Michael S. Kaplan on 18 Nov 2005 10:02 PM:

Well, yes -- just by careful planning of the order of keystrokes -- just make sure you are going up twice before going down again, with your fingers....

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

referenced by

2010/07/02 No plans to deliver a "suck it" message, though Suck It Message Potential (SIMP) would exist

go to newer or older post, or back to index or month or day