From owner-freebsd-hackers@FreeBSD.ORG Wed May 7 21:40:57 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 E03F51065674 for ; Wed, 7 May 2008 21:40:57 +0000 (UTC) (envelope-from jdc@parodius.com) Received: from mx01.sc1.parodius.com (mx01.sc1.parodius.com [72.20.106.3]) by mx1.freebsd.org (Postfix) with ESMTP id D0F398FC12 for ; Wed, 7 May 2008 21:40:57 +0000 (UTC) (envelope-from jdc@parodius.com) Received: by mx01.sc1.parodius.com (Postfix, from userid 1000) id B4BF81CC05B; Wed, 7 May 2008 14:40:57 -0700 (PDT) Date: Wed, 7 May 2008 14:40:57 -0700 From: Jeremy Chadwick To: rmgls@free.fr Message-ID: <20080507214057.GA74435@eos.sc1.parodius.com> References: <20080507153903.41F6C322858@smtp7-g19.free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080507153903.41F6C322858@smtp7-g19.free.fr> User-Agent: Mutt/1.5.17 (2007-11-01) Cc: 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 21:40:58 -0000 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? > > 2. how to get the scancodes? It depends on if you're wanting the actual hard-wired keyboard (on the console), or if you're taking input from a tty/pty. You won't get a true scancode from a tty/pty, but you will get a character (0x00 to 0xFF). Regarding I/O without waiting: there is not a general libc function for this. Garrett mentioned getc(), which blocks (waits). 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. > of course i can poll tje (0x64) keyboard port on a i386 architecture, > but this is not a general method, and it is suited for a distant terminal > for instance. I agree. This method is also very old, and I'd be surprised if it would work with USB keyboards. I would assume it would also interfere with any existing keyboard I/O handler the OS has, but I'm not sure. -- | Jeremy Chadwick jdc at parodius.com | | Parodius Networking http://www.parodius.com/ | | UNIX Systems Administrator Mountain View, CA, USA | | Making life hard for others since 1977. PGP: 4BD6C0CB |