ebiten icon indicating copy to clipboard operation
ebiten copied to clipboard

Proposal: add GetLocalizedKeyName function

Open eliasdaler opened this issue 2 years ago • 3 comments

Suppose that I want to make the game display the message "Press "W" to walk forward". However if the person playing the game has the French layout, I'd like to show "Press "Z" to walk forward" instead (because in AZERTY "Z" is in the same position as "W" on QWERTY)

glfw has glfwGetKeyName function to obtain the name of the key, it looks like we can use it for obtaining this mapping for some platforms.

The interface can be as follows for Ebiten:

func GetLocalizedKeyName(key Key) string { ... }

And finally, the end users will be able to do this:

DisplayMessage(fmt.Sprintf("Press %q to walk forward", ebiten.GetLocalizedKeyName(ebiten.KeyW)))

eliasdaler avatar Dec 19 '21 14:12 eliasdaler

@wasedaigo might want this?

hajimehoshi avatar Dec 22 '21 06:12 hajimehoshi

https://github.com/go-gl/glfw/blob/a6c407ee30a0/v3.3/glfw/input.go#L444

This would work. Unfortunately I need to (re)implement this for Windows (internal/glfwwin)

hajimehoshi avatar Jul 31 '22 13:07 hajimehoshi

Unfortunately there seems no easy portable way to implement this. For example, on browsers, key is a little different thing from glfw.GetKeyName.

Let me change the milestone.

hajimehoshi avatar Aug 13 '22 04:08 hajimehoshi

Hm, how can I implement this for browsers?

EDIT: https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/getLayoutMap

hajimehoshi avatar Dec 19 '22 17:12 hajimehoshi

I've implemented KeyName for desktops and browsers.

For mobiles, I'll create a separate issue.

For consoles, I don't implement this (keyboards are not supported).

hajimehoshi avatar Dec 24 '22 18:12 hajimehoshi