events: keyboard: Add additional predicates.
authorDavid Thompson <dthompson2@worcester.edu>
Thu, 17 Dec 2015 01:44:48 +0000 (20:44 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Thu, 17 Dec 2015 01:44:48 +0000 (20:44 -0500)
* sdl2/events.scm (keyboard-down-event?, keyboard-up-event?): New procedures.

sdl2/events.scm

index 1d40a38..edb9306 100644 (file)
@@ -42,6 +42,8 @@
 
             make-keyboard-event
             keyboard-event?
+            keyboard-down-event?
+            keyboard-up-event?
             keyboard-event-timestamp
             keyboard-event-window-id
             keyboard-event-pressed?
   (scancode keyboard-event-scancode)
   (modifiers keyboard-event-modifiers))
 
+(define (keyboard-down-event? e)
+  "Return #t if E is a key press event."
+  (and (keyboard-event? e)
+       (keyboard-event-pressed? e)))
+
+(define (keyboard-up-event? e)
+  "Return #t if E is a key release event."
+  (and (keyboard-event? e)
+       (not (keyboard-event-pressed? e))))
+
 (define keycode-map
   (alist->hash-table
    `((,ffi:SDLK_UNKNOWN . unknown)