Key events

This commit is contained in:
Hajime Hoshi 2013-12-16 10:02:15 +09:00
parent 099ab48382
commit 72ce849fbd
2 changed files with 14 additions and 0 deletions

View File

@ -72,6 +72,8 @@ func (game *Game) HandleEvent(e interface{}) {
panic(e.Error) panic(e.Error)
} }
game.renderTargets[e.Tag.(string)] = e.Id game.renderTargets[e.Tag.(string)] = e.Id
case ui.KeyStateUpdatedEvent:
fmt.Printf("%v\n", e.Keys)
case ui.MouseStateUpdatedEvent: case ui.MouseStateUpdatedEvent:
game.mouseX, game.mouseY = e.X, e.Y game.mouseX, game.mouseY = e.X, e.Y
} }

View File

@ -121,6 +121,16 @@ func ebiten_ScreenSizeUpdated(nativeWindow unsafe.Pointer, width, height int) {
u.windowEvents.notifyScreenSizeUpdated(e) u.windowEvents.notifyScreenSizeUpdated(e)
}*/ }*/
func (w *Window) keyStateUpdatedEvent() ui.KeyStateUpdatedEvent {
keys := []ui.Key{}
for key, _ := range w.pressedKeys {
keys = append(keys, key)
}
return ui.KeyStateUpdatedEvent{
Keys: keys,
}
}
var cocoaKeyCodeToKey = map[int]ui.Key{ var cocoaKeyCodeToKey = map[int]ui.Key{
123: ui.KeyLeft, 123: ui.KeyLeft,
124: ui.KeyRight, 124: ui.KeyRight,
@ -136,6 +146,7 @@ func ebiten_KeyDown(nativeWindow unsafe.Pointer, keyCode int) {
} }
w := windows[nativeWindow] w := windows[nativeWindow]
w.pressedKeys[key] = struct{}{} w.pressedKeys[key] = struct{}{}
w.notify(w.keyStateUpdatedEvent())
} }
//export ebiten_KeyUp //export ebiten_KeyUp
@ -146,6 +157,7 @@ func ebiten_KeyUp(nativeWindow unsafe.Pointer, keyCode int) {
} }
w := windows[nativeWindow] w := windows[nativeWindow]
delete(w.pressedKeys, key) delete(w.pressedKeys, key)
w.notify(w.keyStateUpdatedEvent())
} }
//export ebiten_MouseStateUpdated //export ebiten_MouseStateUpdated