general i/o question

Mike Meyer mwm-keyword-freebsdhackers2.e313df at mired.org
Wed May 7 22:31:26 UTC 2008


On Wed, 7 May 2008 14:40:57 -0700
Jeremy Chadwick <koitsu at freebsd.org> wrote:

> On Wed, May 07, 2008 at 05:39:00PM +0200, rmgls at free.fr wrote:
> > i need to test (NOWAIT), the presence of keypressed/depressed on a terminal
> > and then read the scan code, like for a piano pc keyboard.
> > 
> > my questions are as follows:
> > 
> > 1. is it a general C function which may scan a terminal without waiting?
> Regarding I/O without waiting: there is not a general libc function for
> this.  Garrett mentioned getc(), which blocks (waits).

getc won't tell you whether a key is pressed or not in any case, just
that a key *has been* pressed when it returns. This question is
normally tied back to some DOS getc-like call that didn't block, but
returned null if a key hadn't been pressed. The standard way to do
that is select() (now poll). The problem with both of those is that -
again - they won't tell you whether or not a key *is* pressed, but
only whether one *has been* pressed.

> You might want to consider seeing if the kqueue/kevent stuff on the BSDs
> will work with pty/tty input.  You can use that to set up an event in
> the kernel which tells the kernel "run function XYZ when I/O is seen on
> this fh/fd".  It's like select() in that respect, but is faster.

Yes, they'll work with it. The question is - can you get the
information about whether or not a key is currently pressed that way?
Since X gets the information, its' there - but it's not clear how
close to the hardware X has to get to get it.

      <mike
-- 
Mike Meyer <mwm at mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org


More information about the freebsd-hackers mailing list