2 (in-package :lambdamundo
)
4 ;; keyboard handling --------------------
6 (defparameter *key-fns
* (make-hash-table)
7 "Hash table to map keypresses to function calls")
9 (defparameter *mouse-free
* t
10 "Indicates whether the mouse pointer is free or not")
12 (defmacro make-key-function
((key action-sym
) &body forms
)
13 "Compile a body and place it in the key hashtable, to be called
14 when the given key is pressed."
15 `(setf (gethash ,key
*key-fns
*)
16 (compile nil
'(lambda (,action-sym
) ,@forms
))))
18 (defun kill-key-function (key)
19 "Remove a key function from the list"
20 (remhash key
*key-fns
*))
22 ;; default quit the window function
24 (glfw:+key-esc
+ action
)
25 (when (= action glfw
:+press
+)
29 (glfw:+key-space
+ action
)
30 (when (= action glfw
:+press
+)
31 (setf *mouse-free
* (not *mouse-free
*))
33 (glfw:enable glfw
:+mouse-cursor
+)
34 (glfw:disable glfw
:+mouse-cursor
+))))
36 (cffi:defcallback lambdamundo-key-callback
37 :void
((key :int
) (action :int
)) (when-funcall (gethash key
*key-fns
*) action
))