Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 May 2008 14:40:57 -0700
From:      Jeremy Chadwick <koitsu@freebsd.org>
To:        rmgls@free.fr
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: general i/o question
Message-ID:  <20080507214057.GA74435@eos.sc1.parodius.com>
In-Reply-To: <20080507153903.41F6C322858@smtp7-g19.free.fr>
References:  <20080507153903.41F6C322858@smtp7-g19.free.fr>

next in thread | previous in thread | raw e-mail | index | archive | help
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 |




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080507214057.GA74435>