Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] KeyboardKey only supports American keyboard #4019

Closed
Kaganox opened this issue May 30, 2024 · 7 comments
Closed

[rcore] KeyboardKey only supports American keyboard #4019

Kaganox opened this issue May 30, 2024 · 7 comments

Comments

@Kaganox
Copy link

Kaganox commented May 30, 2024

I'm using a Europe (German) keyboard.
Its happend in Raylib-cs, but becaus its a port of Raylib i think this problem is still in original Raylib.

If i do this:

if (Raylib.IsKeyDown(KeyboardKey.Z))
{
    Console.WriteLine("Called!");
}

Its happen nothing by pressing Z, but if i press Y the if statement is executing.

This problem is also by int key = Raylib.GetKeyPressed();

int key = Raylib.GetKeyPressed();
Console.WriteLine((KeyboardKey)key).ToString());

Clicked: Y
Output: Z

@Kaganox Kaganox changed the title KeyboardKey only supports American keyboard [raylib] KeyboardKey only supports American keyboard May 30, 2024
@MrScautHD
Copy link
Contributor

I can agree.

@JupiterRider
Copy link
Contributor

I think this is behavior intended. See #2822

@raysan5 raysan5 changed the title [raylib] KeyboardKey only supports American keyboard [rcore] KeyboardKey only supports American keyboard Jun 5, 2024
@raysan5
Copy link
Owner

raysan5 commented Jun 5, 2024

@PizzaGame01 I'm afraid there is not an easy solution to this problem, the keyboard mapping should be managed at GLFW, that raylib uses or at user side. Do you know of another possible solution?

@raysan5
Copy link
Owner

raysan5 commented Jun 22, 2024

If anyone finds this issue and knows of a simple multi-platform solution to address it, please, comment

@raysan5 raysan5 closed this as completed Jun 22, 2024
@MrScautHD
Copy link
Contributor

@PizzaGame01 I'm afraid there is not an easy solution to this problem, the keyboard mapping should be managed at GLFW, that raylib uses or at user side. Do you know of another possible solution?

has SDL 2 the same problem?

@JeffM2501
Copy link
Sponsor Contributor

The problem statement in this issue is flawed, that is why there is confusion.

The keyboard key (KEY_) enum is not the keyname, it's the physical keycode. That enum was named after the American layout, because the enum has to be named something.

The enum can not and should not change based on keyboard layout. it represents physical buttons.
A FPS game on a dvorak keyboard would not use WASD, it'd use ,AEO, because they are in the same physical location.
A raylib game should not be expected to know the layout when checking for physical keys, it should simply check for KEY_W, KEY_A, KEY_D, KEY_S.
Text input is mapped using GetCharPressed and is handled correctly.
What we are missing is a way to get the key name from the platform so that a game can show the mapped key name in things like settings and control bindings.

There should be an API where the user can ask "What is the name of KEY_W", and on dvorak it would return ',', or whatever the characater code is for the keyboard mapping.

GLFW exposes this via glfwGetKeyName, and I'm sure that other platforms do as well.
https://www.glfw.org/docs/3.3/group__input.html#gaeaed62e69c3bd62b7ff8f7b19913ce4f

We should add aconst char* GetKeyName(KeyboardKey key)function to raylib to handle this and let each platform implement it.

This will solve the core issue and provide access to all 3 levels of keyboard info for keys

  • Physical Key (KeyboardKey enum)
  • Typed character (GetCharPressed results)
  • KeyName (new GetKeyName function)

@MrScautHD
Copy link
Contributor

@raysan5 can you may reopen it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants