Subject: RE: questions about keyboard

From: "Xu, Jiang" <[email-masked]>
Date: Wed, 14 Apr 2004 14:56:20 -0600

I do turn on CONFIG_VT, if I don't I will not be able to pass compiling the
keyboard.c and some other stuffs.
Because I did not turn on INPUT_EVDEV, so I did not create the device node
before. 

However, I just gave it a quick try by turning on INPUT_EVDEV and create the
device nodes; and actually I saw response on input/event0!! Thanks!

Now I have some questions:
1.  I have CONFIG_VT on, so why ttyN is not connected to the device? I saw
console.o and tty_io.o, etc.
What may be wrong or did I miss doing some things that I should do?
2.  In the application, how can I know which input/event# the usb keyboard
connects to?
3.  Is there some reference documents about how to read things from
input/event# ? I mean such as how to read key event?

Thanks

John

-----Original Message-----
From: Geert Uytterhoeven [mailto:[email-masked]] 
Sent: Wednesday, April 14, 2004 2:37 PM
To: Xu, Jiang
Cc: Linux/MIPS Development
Subject: RE: questions about keyboard

On Wed, 14 Apr 2004, Xu, Jiang wrote:
> Well, this is the problem.
> For some reasons, none of the /dev/tty /dev/tty0... /dev/console is 
> connected to the keyboard, I have tried listening all of them.  Did I 
> configured something wrong? But kernel seems to be getting the key 
> event from the keyboard. Another question is if it should connect to 
> one of those device nodes, is there anyway I can hack the kernel to 
> see where the key event sent to?

Do you have CONFIG_VT=y? I guess not.

Do you receive anything on /dev/input/eventX?

> -----Original Message-----
> From: Jan-Benedict Glaw [mailto:[email-masked]]
> Sent: Wednesday, April 14, 2004 2:26 PM
> To: [email-masked]
> Subject: Re: questions about keyboard
>
>
> On Wed, 2004-04-14 14:18:18 -0600, Xu, Jiang <[email-masked]> 
> wrote in message 
> <[email-masked]>:
> > However, what I don't get is how can I get the key event from the 
> > kernel?  I tried to listen to all the ttyN, but none of them connect 
> > to
> the keyboard.
> > I wonder how I can write a user space application that can get the 
> > key event?  Could somebody help me out?  Because it is an embedded 
> > device,
> there
> > is no X.
>
> Well, one of /dev/tty, /dev/tty0 or /dev/console should work. If you'd 
> likt to use the new'n'fancy style, use /dev/input/eventX .

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 --
[email-masked]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like
that.
							    -- Linus
Torvalds

---

From: Jan-Benedict Glaw <[email-masked]>
Date: Thu, 15 Apr 2004 10:36:09 +0200

On Wed, 2004-04-14 14:56:20 -0600, Xu, Jiang <[email-masked]>
> 2.  In the application, how can I know which input/event# the usb keyboard

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.

> 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       [email-masked]    . +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));