Unbuffered char reads from App from stdin (keyboard)

Steven Vacca svacca at valcom.com
Tue Feb 19 05:28:28 EST 2002


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 at 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/





More information about the Linuxppc-embedded mailing list