Date: Wed, 7 May 2008 18:04:41 -0400 From: Mike Meyer <mwm-keyword-freebsdhackers2.e313df@mired.org> To: Jeremy Chadwick <koitsu@freebsd.org> Cc: rmgls@free.fr, freebsd-hackers@freebsd.org Subject: Re: general i/o question Message-ID: <20080507180441.008acfe9@bhuda.mired.org> In-Reply-To: <20080507214057.GA74435@eos.sc1.parodius.com> References: <20080507153903.41F6C322858@smtp7-g19.free.fr> <20080507214057.GA74435@eos.sc1.parodius.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 7 May 2008 14:40:57 -0700 Jeremy Chadwick <koitsu@freebsd.org> wrote: > On Wed, May 07, 2008 at 05:39:00PM +0200, rmgls@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@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080507180441.008acfe9>