diff --git a/examples/keyboard/main.go b/examples/keyboard/main.go index 874e48f2e..8173a9445 100644 --- a/examples/keyboard/main.go +++ b/examples/keyboard/main.go @@ -78,11 +78,13 @@ func (g *Game) Draw(screen *ebiten.Image) { screen.DrawImage(keyboardImage.SubImage(r).(*ebiten.Image), op) } - keyStrs := []string{} + var keyStrs []string + var keyNames []string for _, k := range g.keys { keyStrs = append(keyStrs, k.String()) + keyNames = append(keyNames, ebiten.KeyName(k)) } - ebitenutil.DebugPrint(screen, strings.Join(keyStrs, ", ")) + ebitenutil.DebugPrint(screen, strings.Join(keyStrs, ", ")+"\n"+strings.Join(keyNames, ", ")) } func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { diff --git a/input.go b/input.go index bb25b95e6..49258c075 100644 --- a/input.go +++ b/input.go @@ -69,6 +69,10 @@ func IsKeyPressed(key Key) bool { return theInputState.isKeyPressed(key) } +func KeyName(key Key) string { + return ui.KeyName(ui.Key(key)) +} + // CursorPosition returns a position of a mouse cursor relative to the game screen (window). The cursor position is // 'logical' position and this considers the scale of the screen. // diff --git a/internal/glfw/glfw_notwindows.go b/internal/glfw/glfw_notwindows.go index e43b525ec..1b5d3b946 100644 --- a/internal/glfw/glfw_notwindows.go +++ b/internal/glfw/glfw_notwindows.go @@ -273,6 +273,10 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind return theWindows.add(w), nil } +func GetKeyName(key Key, scancode int) string { + return glfw.GetKeyName(glfw.Key(key), scancode) +} + func GetMonitors() []*Monitor { ms := []*Monitor{} for _, m := range glfw.GetMonitors() { diff --git a/internal/ui/input_glfw.go b/internal/ui/input_glfw.go index 411d98b96..8e56b9153 100644 --- a/internal/ui/input_glfw.go +++ b/internal/ui/input_glfw.go @@ -76,3 +76,11 @@ func (u *userInterfaceImpl) updateInputState() error { } return nil } + +func KeyName(key Key) string { + gk, ok := uiKeyToGLFWKey[key] + if !ok { + return "" + } + return glfw.GetKeyName(gk, 0) +}