linux-mips
[Top] [All Lists]

Re: questions about keyboard

To: Linux/MIPS Development <linux-mips@linux-mips.org>
Subject: Re: questions about keyboard
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
Date: Thu, 15 Apr 2004 10:36:09 +0200
In-reply-to: <F71A246055866844B66AFEB10654E7860F1B0D@riv-exchb6.echostar.com>
Mail-followup-to: Linux/MIPS Development <linux-mips@linux-mips.org>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <F71A246055866844B66AFEB10654E7860F1B0D@riv-exchb6.echostar.com>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.5.5.1+cvs20040105i
On Wed, 2004-04-14 14:56:20 -0600, Xu, Jiang <Jiang.Xu@echostar.com>
wrote in message 
<F71A246055866844B66AFEB10654E7860F1B0D@riv-exchb6.echostar.com>:
> 2.  In the application, how can I know which input/event# the usb keyboard
> connects to?

You don't. You can

        - Hope that your keyboard is the one and only device...
        - Read /proc/bus/input/devices - there should be a "kbd" handler
          in the "H: " section
        - select() on all event* devices and just only process
          keypresses generated from "normal" keys.

> 3.  Is there some reference documents about how to read things from
> input/event# ? I mean such as how to read key event?

I don't think there's really good docu available, but it's really
simple. Just open all devices, select() until there's data available (or
just call a blocking read() on it). Something like this should work, but
you'd better add error checking to the open() call...

#include <linux/input.h>

ssize_t ret;
struct input_event my_input;
int fd;

fd = open ("/dev/input/event0", O_RDONLY);
for (;;) {
        ret = read (fd, &my_input, sizeof (my_input));
        if (ret != sizeof (my_input)
                break;

        if (my_input.type != EV_KEY)
                continue;
        /* my_input.code and my_input.type now contain the key and
           press/release state; refer to the #defines in linux/input.h
           for the mapping .code -> ASCII value */
}
close (fd);


-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

Attachment: signature.asc
Description: Digital signature

<Prev in Thread] Current Thread [Next in Thread>