In Lisp I use with-event-loop from cl-sdl2, like this:
(with-event-loop (:method :poll) (:keydown (:keysym keysym) (let ((scancode (scancode-value keysym))) (cond ((scancode= scancode :scancode-space) (format t "Playing Song~%") (sdl2-mixer:play-music music 1)) ((scancode= scancode :scancode-up) (when (< (+ *current-volume* 20) 128) (incf *current-volume* 20) (format t "Current Volume: ~a~%" *current-volume*) (sdl2-mixer:volume-music *current-volume*))) ((scancode= scancode :scancode-down) (when (> (- *current-volume* 20) 0) (decf *current-volume* 20) (format t "Current Volume: ~a~%" *current-volume*) (sdl2-mixer:volume-music *current-volume*)))))) ......
I think the above code is just like some of your code here :
for (;;) {" " while(SDL_PollEvent(&e)) if (e.type == SDL_QUIT) quitted = 1; else if (e.type == SDL_KEYDOWN) switch (e.key.keysym.sym) { case SDLK_q: quitted = 1; break; }
I didn't handle the "holding down" action specifically, so I haven't used something like SDL_GetKeyboardState.
If I were going to do it, I could use the function `keyboard-state-p` as defined here:
(defun keyboard-state-p (scancode) "Whether the key corresponding to the given scancode is currently pressed." (let ((state (nth-value 1 (autowrap:inhibit-string-conversion (sdl2-ffi.functions:sdl-get-keyboard-state nil)))) (scancode-num (autowrap:enum-value 'sdl2-ffi:sdl-scancode scancode))) (c-let ((state :unsigned-char :ptr state)) (= (state scancode-num) 1))))I can see that you're using ECL SFFI in your code, which involves writing C in Lisp, why not using UFFI or CFFI, since it will give us a more Lispy programming experience? Just being curious, because I feel C is too intimidating to me.