[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more flexible READ-CHAR?



   Date: Thu, 14 Mar 91 03:18:40 EST
   From: Eliot Handelman <eliot@clarity.Princeton.EDU>
   To: info-macl@cambridge.apple.com, waander@cs.UMD.EDU
   Subject: more flexible READ-CHAR?
   
   I need a version of READ-CHAR that
   
   1. catches ALL key events (READ-CHAR ignores #\Backspace, for instance)
   
   2. does NOT print to the listener.
   
   
   I've been doing it like this, but this is slow:
   
   (defvar *key-event* nil)
   
   (defobfun (window-key-event-handler *my-window*) (char)
      (setq *key-event* char))
   
   
   (defun my-read-char (&rest ignore)
     (let ((*key-event* nil))
      (loop 
        (when *key-event* (return *key-event*)))))
   
   
   Can someone suggest an improvement? How does READ-CHAR work internally?
   
   --eliot

READ-CHAR calls STREAM-TYI.  The WINDOW-KEY-EVENT-HANDLER for *WINDOW*
sends all keystrokes to the listener.  Hence, you need to write your
own WINDOW-KEY-EVENT-HANDLER (which you did).  The normal way of
handling this is to have a queue of typed characters which is written
into by WINDOW-KEY-EVENT-HANDLER and read from by STREAM-TYI.  I'll
send more details if this doesn't give you enough to go on.

Bill