diff --git a/internal/monogame/monogame.go b/internal/monogame/monogame.go index 6bdf00cda..a1c4c9f00 100644 --- a/internal/monogame/monogame.go +++ b/internal/monogame/monogame.go @@ -114,6 +114,11 @@ func (g *Game) ResetDestination(viewportWidth, viewportHeight int) { g.binding.Call("SetDestination", nil, viewportWidth, viewportHeight) } +func (g *Game) IsKeyPressed(key driver.Key) bool { + // Pass a string of the key since both driver.Key value and XNA's key value are not reliable. + return g.binding.Call("IsKeyPressed", key.String()).Bool() +} + type RenderTarget2D struct { v js.Value binding js.Value diff --git a/internal/uidriver/monogame/input.go b/internal/uidriver/monogame/input.go index c7ddf5733..c58797264 100644 --- a/internal/uidriver/monogame/input.go +++ b/internal/uidriver/monogame/input.go @@ -18,9 +18,11 @@ package monogame import ( "github.com/hajimehoshi/ebiten/internal/driver" + "github.com/hajimehoshi/ebiten/internal/monogame" ) type Input struct { + game *monogame.Game } func (i *Input) CursorPosition() (x, y int) { @@ -56,7 +58,7 @@ func (i *Input) IsGamepadButtonPressed(id int, button driver.GamepadButton) bool } func (i *Input) IsKeyPressed(key driver.Key) bool { - return false + return i.game.IsKeyPressed(key) } func (i *Input) IsMouseButtonPressed(button driver.MouseButton) bool { diff --git a/internal/uidriver/monogame/ui.go b/internal/uidriver/monogame/ui.go index b8e060442..f228b1ae6 100644 --- a/internal/uidriver/monogame/ui.go +++ b/internal/uidriver/monogame/ui.go @@ -39,6 +39,7 @@ func (u *UI) Run(context driver.UIContext) error { defer g.Dispose() u.game = g + u.input.game = g u.context = context u.Graphics().(*graphics.Graphics).SetGame(g) u.updateSize()