defold / defold

Defold is a completely free to use game engine for development of desktop, mobile and web games.
https://www.defold.com
Other
3.94k stars 282 forks source link

wrong key with mac keyboard and Italian layout #4855

Open rsaienz opened 4 years ago

rsaienz commented 4 years ago

BUG DESCRIPTION There is a problem with the Defold input and my Mac keyboard with Italian layout. Almost all non-alphanumeric keys are wrong. Here is a list of pairs (k , a) where k is the key I press on the keyboard and a is the action_id I get (via all.input_binding of @britzl): < , key_grave [minus] , key_slash ò , key_semicolon à , key_singlequote ù , key_backslash è , key_lbracket [plus] , key_rbracket ' , key_minus ì , key_equals

REPRODUCE

  1. add @britzl all.input_binding to an empty project
  2. print the action_id received by pressing the above keys on a mac keyboard with Italian layout

EXPECTED BEHAVIOR The input system should return the keycode (or a displayname of the key being pressed) and not the scancode. Or, in some other way, there should be a way to know the correct character associated with a key on the physical keyboard; this implies that the input system must take into consideration the keyboard layout before sending a key event.

DEFOLD VERSION Version 1.2.169

PLATFORM

beldenfox commented 3 years ago

I looked at the engine code and did a quick test. On the Mac the engine will always generate key codes for input binding as if the keyboard was US QWERTY. On Windows the engine will generate key binding that match the user's chosen keyboard layout. I'm assuming Defold should pick one of these behaviors and be consistent with it. Here's hoping it's the Windows behavior, it's much easier to make the Mac behave like Windows than the other way around.

This should only affect input bindings and not text entry or keyboard equivalents (like Cmd+Q).

britzl commented 3 years ago

Thank you for the feedback @beldenfox ! I agree that it's not very good if we are inconsistent in the way input is handled in the engine.

britzl commented 3 years ago

By the way @beldenfox have you perhaps already formed an opinion on how a PR for this would look?

beldenfox commented 3 years ago

I'm not sure how you want key bindings to work. In Unity key bindings bind to physical locations based on the US QWERTY layout (according to the documentation, I'm not a user). So if you bind WASD to movement actions the same physical key locations will work for movement regardless of language or keyboard layout. There's an API function you can call in-game to retrieve the character actually printed on the user's keyboard at that location to display in the game's user interface.

From what I gather the Unreal Engine binds to characters and not locations so the physical keys bound to a key action move as the keyboard language changes. If a game developer wants the physical key locations to stay the same across layouts they have to provide a different set of bindings for each layout (WASD for English, ZQSD for French, and so forth) or invest in an extension that provides stable key locations (I ran across one sold by Loonyware).

In Godot they decided they needed both behaviors so you can either bind to a Key which moves depending on layout or Physical Key which is pinned to the US QWERTY location and never moves.

Currently Defold behaves like Unity on the Mac and Unreal on Windows. I haven't been able to test Linux.

If Defold was a 3D game engine I would imagine you would want the Unity behavior. I'm not familiar enough with 2D game design to know which model is most appropriate.

JCash commented 3 years ago

Interesting. I would have thought that our desktop users would have noticed the discrepancy earlier (perhaps they have, and I forgot, hmm)

Given our dedication towards backwards compatibility, I'd say if we have two ways of doing it, we might need to support the two ways. It depends a bit on how many users rely on the feature. If there are only a few, and there's an easy way to patch their particular game, we might consider it a bug fix, so we only support one version.

beldenfox commented 3 years ago

It seems the GLFW folks already addressed this issue and fixed it in 3.1. Basically they agree with the Unity behavior. The complete discussion is at https://github.com/glfw/glfw/issues/114#issue-18008307