ebiten: add KeyName (WIP)

Updates #1904
This commit is contained in:
Hajime Hoshi 2022-08-13 13:33:52 +09:00
parent d1b9a0a9a1
commit c74eb058d3
4 changed files with 20 additions and 2 deletions

View File

@ -78,11 +78,13 @@ func (g *Game) Draw(screen *ebiten.Image) {
screen.DrawImage(keyboardImage.SubImage(r).(*ebiten.Image), op) screen.DrawImage(keyboardImage.SubImage(r).(*ebiten.Image), op)
} }
keyStrs := []string{} var keyStrs []string
var keyNames []string
for _, k := range g.keys { for _, k := range g.keys {
keyStrs = append(keyStrs, k.String()) 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) { func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {

View File

@ -69,6 +69,10 @@ func IsKeyPressed(key Key) bool {
return theInputState.isKeyPressed(key) 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 // 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. // 'logical' position and this considers the scale of the screen.
// //

View File

@ -273,6 +273,10 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind
return theWindows.add(w), nil return theWindows.add(w), nil
} }
func GetKeyName(key Key, scancode int) string {
return glfw.GetKeyName(glfw.Key(key), scancode)
}
func GetMonitors() []*Monitor { func GetMonitors() []*Monitor {
ms := []*Monitor{} ms := []*Monitor{}
for _, m := range glfw.GetMonitors() { for _, m := range glfw.GetMonitors() {

View File

@ -76,3 +76,11 @@ func (u *userInterfaceImpl) updateInputState() error {
} }
return nil return nil
} }
func KeyName(key Key) string {
gk, ok := uiKeyToGLFWKey[key]
if !ok {
return ""
}
return glfw.GetKeyName(gk, 0)
}