From 6d78be95569519bcad7d381e4135f76bf5bd31ec Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 1 Apr 2017 12:00:44 -0400 Subject: input: Add keyboard module. * chickadee/input/keyboard.scm: New file. * Makefile.am (SOURCES): Add it. * doc/api.texi (Keyboard): New section. --- Makefile.am | 1 + chickadee/input/keyboard.scm | 29 +++++++++++++++++++++++++++++ doc/api.texi | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 chickadee/input/keyboard.scm diff --git a/Makefile.am b/Makefile.am index 5dfbbb9..0103c2b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,6 +43,7 @@ SOURCES = \ chickadee/utils.scm \ chickadee/audio.scm \ chickadee/input/controller.scm \ + chickadee/input/keyboard.scm \ chickadee/math.scm \ chickadee/math/vector.scm \ chickadee/math/matrix.scm \ diff --git a/chickadee/input/keyboard.scm b/chickadee/input/keyboard.scm new file mode 100644 index 0000000..afc0435 --- /dev/null +++ b/chickadee/input/keyboard.scm @@ -0,0 +1,29 @@ +;;; Chickadee Game Toolkit +;;; Copyright © 2017 David Thompson +;;; +;;; Chickadee is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published +;;; by the Free Software Foundation, either version 3 of the License, +;;; or (at your option) any later version. +;;; +;;; Chickadee is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see +;;; . + +(define-module (chickadee input keyboard) + #:use-module ((sdl2 input keyboard) #:prefix sdl2:) + #:export (key-pressed? + key-released?)) + +(define (key-pressed? key) + "Return #t if KEY is currently being pressed." + (sdl2:key-pressed? key)) + +(define (key-released? key) + "Return #t if KEY is not currently being pressed." + (sdl2:key-released? key)) diff --git a/doc/api.texi b/doc/api.texi index 126d7dd..74ccfff 100644 --- a/doc/api.texi +++ b/doc/api.texi @@ -378,6 +378,24 @@ values are: @node Input @section Input +Chickadee can handle input events from the keyboard, mouse, and game +controllers. + +@menu +* Keyboard:: Keyboard input. +@end menu + +@node Keyboard +@subsection Keyboard + +@deffn {Scheme Procedure} key-pressed? @var{key} +Return @code{#t} if @var{key} is currently being pressed. +@end deffn + +@deffn {Scheme Procedure} key-released? @var{key} +Return @code{#t} if @var{key} is not currently being pressed. +@end deffn + @node Math @section Math -- cgit v1.2.3