ebiten/ui/glfw/keyboard.go

29 lines
584 B
Go
Raw Normal View History

2014-12-06 19:27:55 +01:00
package glfw
import (
glfw "github.com/go-gl/glfw3"
2014-12-07 14:10:04 +01:00
"github.com/hajimehoshi/ebiten/input"
2014-12-06 19:27:55 +01:00
)
type keyboard struct {
2014-12-07 20:22:50 +01:00
keyPressed [input.KeyMax]bool
2014-12-06 19:27:55 +01:00
}
func (k *keyboard) IsKeyPressed(key input.Key) bool {
2014-12-07 20:22:50 +01:00
return k.keyPressed[key]
2014-12-06 19:27:55 +01:00
}
2014-12-07 14:10:04 +01:00
var glfwKeyCodeToKey = map[glfw.Key]input.Key{
glfw.KeySpace: input.KeySpace,
glfw.KeyLeft: input.KeyLeft,
glfw.KeyRight: input.KeyRight,
glfw.KeyUp: input.KeyUp,
glfw.KeyDown: input.KeyDown,
2014-12-06 19:27:55 +01:00
}
func (k *keyboard) update(window *glfw.Window) {
2014-12-06 19:27:55 +01:00
for g, u := range glfwKeyCodeToKey {
2014-12-07 20:22:50 +01:00
k.keyPressed[u] = window.GetKey(g) == glfw.Press
2014-12-06 19:27:55 +01:00
}
}