RE: Unbuffered char reads from App from stdin (keyboard)

From: Steven Vacca <hidden>
Date: 2002-02-18 18:28:28

FYI (For Y'all's Info):

Here's what I've done.

I wanted to check if 1 or more keys have been pressed, and if so,
get just the next available key in the buffer.
I then wanted to process that key before echoing it to the
terminal, if at all, for nth-degree of control.

- I used termios to disable console Cannonical mode and Echoes.
- I used fcntl() to make stdin Non_Blocking, since, if there's no
  key in the buffer, read() will block.
- I then use:

	read(0,&key,1);

to read just the next key, without blocking when there is no key
in the buffer.


ShutEyeThinkin




-----Original Message-----
From:	Steven Vacca [SMTP:svacca@valcom.com]
Sent:	Friday, February 15, 2002 10:10 AM
To:	LinuxEmbeddedMailList (E-mail)
Subject:	Unbuffered char reads from App from stdin (keyboard)

App and Linux kernel 2.2.13 running on mpc860T.

I would like to know the best way, from inside my GNU C App,
to sense if there's a keyboard key pressed.  Something
similar to kbhit() in Microsoft C.  I would like to have a particular
thread execute a loop continuously and only when a key
is present, do a getc() or getchar(), or gets(), and the like.

What is the best way to accomplish this?
Is there a way to make stdin unbuffered?

Thanks,

ShutEyeThinkin

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help