DirectInput and localization

Started by
4 comments, last by Spoonbender 18 years, 10 months ago
Been playing around with DirectInput lately, but there's one thing I'm wondering about. How does it deal with international keyboards? How do I detect which non-US keys are pressed? As far as I know, I get an array of 255 chars, each representing an actual key on the keyboard, rather than a virtual key or ascii value. Then there are macros defined to map the names of each key to the appropriate array index value (DIK_A, or DIK_SUBTRACT, for example.) But they're only defined for the characters available on a normal US keyboard. What if the user presses, say, Ø or ½ or another key that doesn't exist on US keyboards? Presumably one of the 255 entries in the array wil be set, but how do I know which key that actually refers to? I might want to show which key was pressed (maybe to show the current key bindings when you're configuring controls, or maybe a tutorial wants to display which key you should press to perform some new action) So how would you do that in DirectInput? How would I find out, when some arbitrary key is pressed, what it actually *means*? Of course, many games don't deal with the issue at all, and just uses the standard US keymapping, forcing international players to figure out that when the game tells you to hit ´, it actually means ½, and when it says to press @, you need to use " instead. That's what I'd like to avoid, if possible. ;)
Advertisement
First, just nit-picking, but you get an array of 256 bytes, not 255. (Although, I don't think it actually uses byte zero.)

If you look here and here, you will see that there actually are some key defines for non-US keyboards. Unfortunately, there is no way to know whether a particular key actually exists on a particular keyboard.

Generally, you would choose a set of keys common to all keyboards. Otherwise, you would have to determine through experimentation what keys are available on particular keyboards and document the alternatives for "non-standard" keys.
Quote:Original post by Dave Hunt
First, just nit-picking, but you get an array of 256 bytes, not 255. (Although, I don't think it actually uses byte zero.)

Doh, right... *Feels stupid*

Quote:
Generally, you would choose a set of keys common to all keyboards. Otherwise, you would have to determine through experimentation what keys are available on particular keyboards and document the alternatives for "non-standard" keys.

But then what do you do if the player assigns, say, Å to be their, say, 'strafe left' key? Yes, you can easily just run through the array to find out which of the 256 entries have that bit set, and just use that as the strafe left key in the future, but you usually want to also show the appropriate character in a list of the controls, so the player can see which keys are assigned to what. That means you have to find out that this array index represents an Å on this keyboard. How do you do that?
You can use IDirectInputDevice8::GetObjectInfo() to retrieve the name associated with a key (through the tszName member of DIDEVICEOBJECTINSTANCE). I'm not sure if that value is localized, but it's worth a try.
That value is localized. It gives you a nice descriptive name of the key.

Basically always enumerate all devices, of every device enumerate all objects and you have all keys/buttons/gamepads/whatever in a list.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Ah, thanks, both of you. That's just what I was looking for. :)

This topic is closed to new replies.

Advertisement