Consistent handling of hotkeys in other languages

Started by
3 comments, last by Zipster 8 years, 5 months ago

I recently came across an interesting issue with how we handle hotkey mapping under international keyboard layouts, as was wondering if others have encountered a similar issue and how they dealt with it.

Right now we use some common hotkey groupings as defaults in our game (WASD, QWERTY, etc.). However we noticed that if the user changes their active keyboard layout to something else, like Turkish, these defaults no longer work that well because we map from virtual keys, and these virtual keys are only physically grouped together on a handful of keyboard layouts (U.S. in our case).

The user can always remap their keys, but I'm hoping to come up with some sort of solution to automatically map the default virtual key assignments from the assumed U.S. keyboard layout to the active keyboard layout, at the very least to preserve the usefulness of the defaults for as many players as possible. However the more I look into it, the less feasible it seems.

Does anyone have any experience with this issue? Did you find a solution/workaround, or did you just accept that your default keyboard bindings might suck for some international users and have them re-bind their keys?

Advertisement

Virtual keys have the same physical position in every keyboard layout. So the WASD virtual keys will be on the upper left part on every keyboard. However the text on the actual keys will be different. This is ideal for game control keys, because their position is important, not the text on them. And virtual keys can handle special keys like shift, ctrl etc too.

Off course on the keyboard binding screen you have to translate the name of the virtual key based on the actual keyboard layout with the OS.

If you want to use a textual input, you shouldn't use virtual keys at all. There are many different input methods in different languages that you probably don't want handle. You should use the unicode character codes from the windows messages.

Virtual keys have the same physical position in every keyboard layout.

I was initially under this impression as well, but unfortunately it doesn't appear to be the case. It's easy enough to demonstrate, just breakpoint your WM_KEYDOWN handler and press a key -- such as 'Q' -- with an 'English - US' keyboard set. The virtual key code is 0x51, as you'd expect. Now use the language bar to switch the keyboard to something like 'Turkish (Turkey) - Turkish F'. The same 'Q' key now has a virtual key code of 0x46, which is what you'd expect from the 'F' key. The OEM codes can get especially jumbled.


The user can always remap their keys, but I'm hoping to come up with some sort of solution to automatically map the default virtual key assignments from the assumed U.S. keyboard layout to the active keyboard layout

^^ You already have the best solution.

Assuming you've got a global audience you should have people familiar with that region who can inform you about common shortcuts. Assuming Windows, you can look at Windows keyboard layouts to see what they are mapped to physically, and you can use GetKeyboardLayout() to see what is currently in use.

If the result of GetKeyboardLayout() is one you recognize then default to that layout. Otherwise, use your game's default.

After you've picked your default, allow the user to remap their keys to anything they want, or to switch between any of the prebuilt defaults you have created.


...you can look at Windows keyboard layouts to see what they are mapped to physically...

Thanks for the reference!

I figured that we might just have to set up a few common defaults for our core supported languages, but just wanted to do my due diligence first and see if we couldn't make it easier and more automated for our designers and users :)

This topic is closed to new replies.

Advertisement