Problem with recognizing letter key presses in PCs with multilanguages?

Started by mmm_bot, Tue 28/04/2015 16:47:06

Previous topic - Next topic

mmm_bot

So, I have a code that check whether the player click the letter A, for example - But this will not work when the PC is set to a language that's not English. I use this to check whether the player clicked A:
Code: ags

function on_key_press(eKeyCode keycode) {
[...}
 if (keycode ==  eKeyA)


Is there another way to check for a key press? I would like to avoid a message like "Please set your language to English to enable Caps Lock" if possible...

Thanks! :)

Grok

Code: ags
if ( IsKeyPressed(eKeyA) )


Don't know if this will make any difference for your problem, but you could try it out and see.

Monsieur OUXX

I guess the whole question is :
1. Do you want to check if the player pressed the letter which position on the keyboard is the same position as the position of letter "A" on QWERTY keyboards?
OR
2. Do you want to check if the player entered an "A" no matter his keyboard.


If you're trying to achieve 2., then you don't need to do anything. No matter his keyboard, if his Windows is set properly, then if he presses "A" on his keyboard, then AGS will read the letter "A".
If you're trying to achieve 1., then there's no easy solution except from create custom settings in your game for all expected keyboards.


Two workarounds though :
- Ask the player to press "Left Alt + Left shift" in-game. That's a Windows keystroke that will switch to English keyboard. Try it. For example if the user's keyboard is an AZERTY keyboard, it instantly becomes a QWERTY keyboard.
- If you're just interested in the WASD keys (like most game), then simply ask the player which keyboard he has at game start, and in your code, replace eKayA with eKeyQ, and eKeyW with eKeyZ, where needed. That ought to be enough to manage WASD on a AZERTY keyboard.

 

Crimson Wizard

Quote from: Monsieur OUXX on Wed 29/04/2015 08:58:44
- Ask the player to press "Left Alt + Left shift" in-game. That's a Windows keystroke that will switch to English keyboard. Try it. For example if the user's keyboard is an AZERTY keyboard, it instantly becomes a QWERTY keyboard.
The key combo for switching keyboard mode can be different. For example, I have Alt + Shift to change the language.

There is technically a way to get actual key pressed, regardless of keyboard mode. I know there is on lower level (system API), but I am not sure if it's possible in AGS script. Someone might have a look at what engine does to keyboard.

mmm_bot

Thanks guys.
I guess I could ask the player to make sure he has English selected, it just feels kind of cumbersome... The problem is less with QWERY vs. AZERTY and more with multiple languages. I found specifically that there's a problem with Hebrew keyboards (AGS automatically switches the keyboard to the Hebrew one when the game is started for some reason, even if it was English before.)
I'll look into it through. If I won't find another solution I'll just ask players to make sure English is selected (though I wish there was a way to detect the current language so that I won't bother all players with such a message.)

SMF spam blocked by CleanTalk