From owner-freebsd-hackers@FreeBSD.ORG Wed May 7 22:31:26 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 755C31065678 for ; Wed, 7 May 2008 22:31:26 +0000 (UTC) (envelope-from mwm-keyword-freebsdhackers2.e313df@mired.org) Received: from mired.org (five.mired.org [66.92.153.75]) by mx1.freebsd.org (Postfix) with ESMTP id 1B7268FC14 for ; Wed, 7 May 2008 22:31:25 +0000 (UTC) (envelope-from mwm-keyword-freebsdhackers2.e313df@mired.org) Received: (qmail 12503 invoked by uid 1001); 7 May 2008 18:05:09 -0400 Received: from bhuda.mired.org (bhuda [192.168.195.1]) by bhuda (tmda-ofmipd) with ESMTP; Wed, 07 May 2008 18:05:08 -0400 Date: Wed, 7 May 2008 18:04:41 -0400 To: Jeremy Chadwick 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> Organization: Meyer Consulting X-Mailer: Claws Mail 3.4.0 (GTK+ 2.12.9; amd64-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Mike Meyer Cc: rmgls@free.fr, freebsd-hackers@freebsd.org Subject: Re: general i/o question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 May 2008 22:31:26 -0000 On Wed, 7 May 2008 14:40:57 -0700 Jeremy Chadwick 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. 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