From: thorsten kracht
Subject: ext:with-keyboard and listen
Date: 
Message-ID: <ctq47p$jbb6$1@claire.desy.de>
Dear all,
I am using Clisp under Linux and I like to use (listen) on
the EXT:*KEYBOARD-INPUT* stream. The following piece of
code is a small extension to what I got 2 day ago from
Pascal Bourguignon:

(defun inkey ()
    (if (listen EXT:*KEYBOARD-INPUT*)
        (system::input-character-char
	(read-char EXT:*KEYBOARD-INPUT*))
      nil))

(EXT:WITH-KEYBOARD
  (loop
    (let ((ch (inkey)))
      (if (not (null ch))
	 (print `(reacting upon ,ch))
	 (print "doing something else"))
      (if (and ch (char= #\return ch)) (return))
      (sleep 0.5))))

The idea is basically to react to some keystrokes from the terminal
and if there are none to do something else.
If I run the code and type 'abc#\Return', i get

"doing something else"
"doing something else"
"doing something else"
(REACTING UPON #\b)
(REACTING UPON #\c)
(REACTING UPON #\Return)

It seems that 'a' has been eaten up by (listen) and after
(listen) returned 't' once it always does, even if there is
no more input. That means: I can make a long break between
'b' and 'c' without having (listen) return nil.

I appreciate and help, thanks in advance, Thorsten

From: Sam Steingold
Subject: Re: ext:with-keyboard and listen
Date: 
Message-ID: <usm4fqarp.fsf@gnu.org>
> * thorsten kracht <···············@qrfl.qr> [2005-02-02 09:50:01 +0100]:
>
> I am using Clisp under Linux and I like to use (listen) on the
> EXT:*KEYBOARD-INPUT* stream.
>
> It seems that 'a' has been eaten up by (listen) and after (listen)
> returned 't' once it always does, even if there is no more input. That
> means: I can make a long break between 'b' and 'c' without having
> (listen) return nil.

WFM on linux with both cvs head and 2.33.1:



"doing something else"
"doing something else"
"doing something else"
"doing something else"
"doing something else"
"doing something else"
(REACTING UPON #\a)
"doing something else"
"doing something else"
"doing something else"
(REACTING UPON #\s)
"doing something else"
(REACTING UPON #\d)
"doing something else"
(REACTING UPON #\f)
(REACTING UPON #\g)
(REACTING UPON #\h)
(REACTING UPON #\j)
(REACTING UPON #\k)
"doing something else"
(REACTING UPON #\Return)
NIL



-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Your mouse has moved - WinNT has to be restarted for this to take effect.
From: thorsten kracht
Subject: Re: ext:with-keyboard and listen
Date: 
Message-ID: <4201164E.60504@desy.de>
Sam Steingold wrote:
>>* thorsten kracht <···············@qrfl.qr> [2005-02-02 09:50:01 +0100]:
>>
>>I am using Clisp under Linux and I like to use (listen) on the
>>EXT:*KEYBOARD-INPUT* stream.
>>
>>It seems that 'a' has been eaten up by (listen) and after (listen)
>>returned 't' once it always does, even if there is no more input. That
>>means: I can make a long break between 'b' and 'c' without having
>>(listen) return nil.
> 
> 
> WFM on linux with both cvs head and 2.33.1:
> 
> 
> 
> "doing something else"
> "doing something else"

Thanks for your answer, after reading your posted message
I upgraded Clisp from 2.30 to 2.33 and was able to reproduce
Your result.
Thanks again, with best regards, Thorsten
From: Pascal Bourguignon
Subject: Re: ext:with-keyboard and listen
Date: 
Message-ID: <877jlrfdph.fsf@thalassa.informatimago.com>
thorsten kracht <···············@desy.de> writes:

> Dear all,
> I am using Clisp under Linux and I like to use (listen) on
> the EXT:*KEYBOARD-INPUT* stream. The following piece of
> code is a small extension to what I got 2 day ago from
> Pascal Bourguignon:
> 
> (defun inkey ()
>     (if (listen EXT:*KEYBOARD-INPUT*)
>         (system::input-character-char
> 	(read-char EXT:*KEYBOARD-INPUT*))
>       nil))
> 
> (EXT:WITH-KEYBOARD
>   (loop
>     (let ((ch (inkey)))
>       (if (not (null ch))
> 	 (print `(reacting upon ,ch))
> 	 (print "doing something else"))
>       (if (and ch (char= #\return ch)) (return))
>       (sleep 0.5))))
> 
> The idea is basically to react to some keystrokes from the terminal
> and if there are none to do something else.
> If I run the code and type 'abc#\Return', i get
> 
> "doing something else"
> "doing something else"
> "doing something else"
> (REACTING UPON #\b)
> (REACTING UPON #\c)
> (REACTING UPON #\Return)
> 
> It seems that 'a' has been eaten up by (listen) and after
> (listen) returned 't' once it always does, even if there is
> no more input. That means: I can make a long break between
> 'b' and 'c' without having (listen) return nil.
> 
> I appreciate and help, thanks in advance, Thorsten

It works here.



However, I have a problem with X and the keyboard: when I don't type
on the keyboard for a long time, it seems the Compose key gets
activated, which means that the first two key I type are usually
dropped (or if I happen to type a composition, composed).  I don't
have any cat and no piles of papers on my desk.

Perhaps you've got a similar problem with your keyboard driver?

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The rule for today:
Touch my tail, I shred your hand.
New rule tomorrow.