Detecting keyboard layout (QWERTY, Colemak, etc.) in ActionScript 3

891 views Asked by At

I'm developing a game in AS3 and would like to set the game to bind movement to WASD if the player's keyboard is QWERTY, WARS if it's Colemak, etc. Is this possible, and if so, what are some ways that I could implement this?

2

There are 2 answers

0
Strille On BEST ANSWER

It's not possible to detect keyboard layout in AS3.

What you could do is check the flash.system.Capabilities.language property and based on the language code pre-select the likely keyboard layout. It's obviously not reliable, so you need to let the user be able to change setting.

For instance, French language most likely means the user is in a French speaking region of the world. But while France/Belgium/Luxembourg typically uses AZERTY, Swiss French most likely means a QWERTZ layout (Source: http://en.wikipedia.org/wiki/QWERTZ).

Therefore, a slightly better approach is to detect the country instead of the language setting. But country detection cannot be done with pure AS3, you need a call a server-side script (which in turn uses IP address lookup to determine country).

Not sure it's worth all this hassle, I would simply default to QWERTY since it's the most common.

0
Focusless On

This is a pretty hacky solution I just thought of by reading this so i don't really know if it works that well... But you could create an invisible TextField that you set focus on with stage.focus so that whatever the user types gets in there. Then you can have a keyboardEvent Listener for released buttons that takes the value from the TextField and resets the textfields text.