[comp.sys.amiga.tech] Non-blocking keyboard reads

wen@husc4.HARVARD.EDU (A. Wen) (01/17/89)

I've been mulling over ways to do non-blocking keyboard reads without
polling the keyboard; is there any way that I can be signalled when the
console device has input available short of creating a new task to block 
for input and then signal its parent process?

That is, if I am waiting for the timer to wake me up, but I need to be notified 
of any keystrokes that may occur in the meantime, is there anything simple
(short of busy-waiting) that I can do?


--
A. Wen          wen@husc4.HARVARD.EDU  wen@husc4.BITNET  {seismo!harvard!husc4}
  "The fact that I believe in my own free will was completely predetermined."

jesup@cbmvax.UUCP (Randell Jesup) (01/18/89)

In article <1004@husc6.harvard.edu> wen@husc4.UUCP (A. Wen) writes:
>I've been mulling over ways to do non-blocking keyboard reads without
>polling the keyboard; is there any way that I can be signalled when the
>console device has input available short of creating a new task to block 
>for input and then signal its parent process?

	Well, if you want the console.device (as opposed to RAWKEYS or
VANILLAKEYS), a seperate task is probably the way to go.  The only other
way is to do asynch io, and use the signal bit of the replyport to know when
a read has completed.  (Use SendIO or BeginIO, then when you get the signal,
check the message with CheckIO, and if it completed use WaitIO (which will
remove it from the port) or GetMsg(port) if no other messages use that port).

-- 
Randell Jesup, Commodore Engineering {uunet|rutgers|allegra}!cbmvax!jesup

aaron@madnix.UUCP (Aaron Avery) (01/18/89)

In article <1004@husc6.harvard.edu> wen@husc4.UUCP (A. Wen) writes:
>That is, if I am waiting for the timer to wake me up, but I need to be notified
>of any keystrokes that may occur in the meantime, is there anything simple
>(short of busy-waiting) that I can do?

Absolutely. You arrange for the timer message to come into one message port
which has its own sigbit, and you arrange for the keyboard message to come
in a different port, which has its own different sigbit. There are many ways
to arrange for those keyboard messages, too. One would be accessing the
console.device directly. Also, you can use the keyboard.device, or intuition's
RAWKEY events coming into an IDCMP port.

Now, you need to wait for these signals. You want to use the Exec function
Wait(). It takes a single argument which is a signal mask, indicating all of
the sigbits you want to be awakened for. When Wait() returns, it returns a
mask of all signals to which you're responding, by which you can tell why
you were awakened. For a better description, please look up Wait() in your
nearest Rom Kernel Manual.

-- 
Aaron Avery, ASDG Inc.         "A mime is a terrible thing to waste."
                                                             -- Robin Williams
ARPA: madnix!aaron@cs.wisc.edu   {uunet|ncoast}!marque!
UUCP:   {harvard|rutgers|ucbvax}!uwvax!astroatc!nicmad!madnix!aaron

rosenbergr@abo.fi (Robin Rosenberg) (01/19/89)

In article <1004@husc6.harvard.edu>, wen@husc4.HARVARD.EDU (A. Wen) writes:
> I've been mulling over ways to do non-blocking keyboard reads without
> polling the keyboard; is there any way that I can be signalled when the
> console device has input available short of creating a new task to block 
> for input and then signal its parent process?
> 
> That is, if I am waiting for the timer to wake me up, but I need to be notified 
> of any keystrokes that may occur in the meantime, is there anything simple
> (short of busy-waiting) that I can do?
> 

You could do it several ways. If you are using windows with IDCMP you might
wait for VANILLA or RAWKEY messages (whichever you put into the IDMCP Flags).
What I think you missed is the fact that you can do *asynchronous* device io.
Use the console device. This will decode the keyboard correctly and give you
funtion keys as well. You SendIO READ requests to the console device. The
device will signal you when it has something to deliver. When you get the
signal you get the reply with WaitIO(). There is an example in RKM Libraries
and devices. If I'm not mistaken it also works. 

------
Robin Rosenberg,	Abo Akademy, FINLAND
email: <rosenbergr@abo.fi> 

shimoda@infohh.rmi.de (Markus Schmidt) (01/19/89)

In article <1004@husc6.harvard.edu> wen@husc4.UUCP (A. Wen) writes:
>That is, if I am waiting for the timer to wake me up, but I need to be notified 
>of any keystrokes that may occur in the meantime, is there anything simple
>(short of busy-waiting) that I can do?

Create a Port an d IOtwio 
Create a port and two messages for the port. Use one of the
messages for the timer.device, the other for the console.device 
(creating both messages for the one port).

The WaitPort(yourPort) and see what arrived:
msg= GetMsg(yourPort);
if (msg==timerMsg) {
   ... timer stuff ...
}
else
if (msg==consoleMsg) {
   ... keystuff ...
}
else {
   ... curse and wait for another message ...
}

Cu
Markus