

Determine if a key has been pressed and store this in a variable.

If no key has been pressed, the program should continue without waiting.




(defun keypress-check ()
  (with-screen (scr :input-echoing nil :input-blocking nil :input-buffering nil :enable-function-keys t)
    (loop
      ;; Determine if a key has been pressed ...
      (if (key-pressed-p scr)
          ;; ... and store this in a variable.
          (let ((ch (get-char scr)))
            ;; exit the loop by pressing q.
            (if (eql (code-char ch) #\q)
                (return)
                (princ (code-char ch) scr)))
          (progn
            ;; If no key has been pressed, the program should continue without waiting.
            (princ #\. scr)
            (refresh scr)
            ;; we wait anyway to spare the CPU.
            (sleep 0.15))))))