adventuregamestudio / ags

AGS editor and engine source code
Other
697 stars 159 forks source link

Investigate if it's possible to support locale-independent keycodes in the "old key mode" #1751

Open ivan-mogilko opened 2 years ago

ivan-mogilko commented 2 years ago

Somehow I did not notice this earlier, but the "new key handling" mode in AGS 3.6.0 apparently fixes an old engine bug where the letter keycodes depend on the active system locale. That is, if you take any previous version of AGS and make a script which tests for letter codes (a-z) in on_key_press - that may cease working if you switch to a different system language that does not use latin characters, as the keycodes would be ascii/ansi codes of the character in different charset. In AGS 3.6.0 however, they are handled the same regardless of the system language, so long as you have "Use old-style key handling" disabled in the game settings. (See #1563 and #1571)

This might be interesting to investigate if it's possible to make this work regardless of the "key handling" mode. The purpose of this mode was to receive separate key presses and modifiers strictly corresponding to each of them; so it's formally not related to the locale problem. Another purpose would be to run older games with the new engine and not depend on locale.

This needs to be done carefully to not break existing keyboard handling. Right now engine handles 2 SDL events: SDL_KEYDOWN and SDL_TEXTINPUT, and decides which to pass further into the engine based on the OPT_KEYHANDLEAPI option. There was some reason why it's done how it's done now, some information may be found in the older discussion on SDL2 port: https://github.com/adventuregamestudio/ags/issues/1096#issuecomment-715880187

Also see just in case, as related to the key input: #1561

fernewelten commented 2 years ago

if you take any previous version of AGS and make a script which tests for letter codes (a-z) in on_key_press - that may cease working if you switch to a different system language, as the keycodes would be ascii/ansi codes of the character.

I don't quite understand. The bottom row of a German keyboard starts with 'Y' whilst a standard English keyboard has a 'Z' in this location, and a French keyboard has a 'W' there. So what is supposed to happen when I hit this key? Get the keycode for 'Z' irrespective of the system language?

ivan-mogilko commented 2 years ago

I don't quite understand. The bottom row of a German keyboard starts with 'Y' whilst a standard English keyboard has a 'Z' in this location, and a French keyboard has a 'W' there. So what is supposed to happen when I hit this key? Get the keycode for 'Z' irrespective of the system language?

No, the difference in keyboard layouts is a completely separate problem (at least as far as i understand). There's already at least one ticket refering to it: #1391

What I was refering to is that AGS received character codes produced by keys rather than the key codes. Thus the resulting code would depend on current system language. For latin language group you would likely see no difference, this will become noticeable if you use e.g. Cyrillic, Arabic, Thai and so forth. EDIT: updated the first post to clarify this.