ebiten/ui/glfw/keyboard.go
2014-12-08 04:23:00 +09:00

29 lines
584 B
Go

package glfw
import (
glfw "github.com/go-gl/glfw3"
"github.com/hajimehoshi/ebiten/input"
)
type keyboard struct {
keyPressed [input.KeyMax]bool
}
func (k *keyboard) IsKeyPressed(key input.Key) bool {
return k.keyPressed[key]
}
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,
}
func (k *keyboard) update(window *glfw.Window) {
for g, u := range glfwKeyCodeToKey {
k.keyPressed[u] = window.GetKey(g) == glfw.Press
}
}