From 6c5542673a45a29b9c1b8b9117fb3b270cc32196 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Fri, 19 Apr 2019 16:21:04 -0700 Subject: [PATCH] Remove ScreenshotKey Event, Add F* Key Handlers * The F3 key now toggles the Debug Overlay, which is now OFF by default. * The F4 key now toggles the Debug Collision Boxes feature. --- sdl/events.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/sdl/events.go b/sdl/events.go index e5a76fb..3ec1a92 100644 --- a/sdl/events.go +++ b/sdl/events.go @@ -19,6 +19,14 @@ var ( // Poll for events. func (r *Renderer) Poll() (*events.State, error) { s := r.events + + // helper function to push keyboard key names on keyDown events only. + pushKey := func(name string, state uint8) { + if state == 1 { + s.KeyName.Push(name) + } + } + for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { case *sdl.QuitEvent: @@ -103,8 +111,30 @@ func (r *Renderer) Poll() (*events.State, error) { continue } s.EnterKey.Push(t.State == 1) + case sdl.SCANCODE_F1: + pushKey("F1", t.State) + case sdl.SCANCODE_F2: + pushKey("F2", t.State) + case sdl.SCANCODE_F3: + pushKey("F3", t.State) + case sdl.SCANCODE_F4: + pushKey("F4", t.State) + case sdl.SCANCODE_F5: + pushKey("F5", t.State) + case sdl.SCANCODE_F6: + pushKey("F6", t.State) + case sdl.SCANCODE_F7: + pushKey("F7", t.State) + case sdl.SCANCODE_F8: + pushKey("F8", t.State) + case sdl.SCANCODE_F9: + pushKey("F9", t.State) + case sdl.SCANCODE_F10: + pushKey("F10", t.State) + case sdl.SCANCODE_F11: + pushKey("F11", t.State) case sdl.SCANCODE_F12: - s.ScreenshotKey.Push(t.State == 1) + pushKey("F12", t.State) case sdl.SCANCODE_UP: s.Up.Push(t.State == 1) case sdl.SCANCODE_LEFT: