mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
Key events
This commit is contained in:
parent
099ab48382
commit
72ce849fbd
@ -72,6 +72,8 @@ func (game *Game) HandleEvent(e interface{}) {
|
||||
panic(e.Error)
|
||||
}
|
||||
game.renderTargets[e.Tag.(string)] = e.Id
|
||||
case ui.KeyStateUpdatedEvent:
|
||||
fmt.Printf("%v\n", e.Keys)
|
||||
case ui.MouseStateUpdatedEvent:
|
||||
game.mouseX, game.mouseY = e.X, e.Y
|
||||
}
|
||||
|
@ -121,6 +121,16 @@ func ebiten_ScreenSizeUpdated(nativeWindow unsafe.Pointer, width, height int) {
|
||||
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{
|
||||
123: ui.KeyLeft,
|
||||
124: ui.KeyRight,
|
||||
@ -136,6 +146,7 @@ func ebiten_KeyDown(nativeWindow unsafe.Pointer, keyCode int) {
|
||||
}
|
||||
w := windows[nativeWindow]
|
||||
w.pressedKeys[key] = struct{}{}
|
||||
w.notify(w.keyStateUpdatedEvent())
|
||||
}
|
||||
|
||||
//export ebiten_KeyUp
|
||||
@ -146,6 +157,7 @@ func ebiten_KeyUp(nativeWindow unsafe.Pointer, keyCode int) {
|
||||
}
|
||||
w := windows[nativeWindow]
|
||||
delete(w.pressedKeys, key)
|
||||
w.notify(w.keyStateUpdatedEvent())
|
||||
}
|
||||
|
||||
//export ebiten_MouseStateUpdated
|
||||
|
Loading…
Reference in New Issue
Block a user