Subject: Generating keypresses from usbhidaction ?
To: None <netbsd-help@netbsd.org>
From: Martijn van Buul <pino@dohd.org>
List: netbsd-help
Date: 01/20/2007 12:35:08
Hello

I got a new keyboard - a "Microsoft Natural Ergonomic Keyboard 4000 V1.0".
Like most keyboards these days, it comes with extra bells and whistles, like
a slider and a few extra buttons, including the infamous f-lock, which I like 
to use (or: in case of f-lock, make harmless).

To my suprise, this keyboard is actually a composite device:

uhidev0 at uhub0 port 9 configuration 1 interface 0
uhidev0: Microsoft NaturalM-BM-. Ergonomic Keyboard 4000, rev 2.00/1.73, addr 2, iclass 3/1
ukbd0 at uhidev0
wskbd1 at ukbd0 mux 1
wskbd1: connecting to wsdisplay0
uhidev1 at uhub0 port 9 configuration 1 interface 1
uhidev1: Microsoft NaturalM-BM-. Ergonomic Keyboard 4000, rev 2.00/1.73, addr 2, iclass 3/0
uhidev1: 1 report ids
uhid0 at uhidev1 reportid 1: input=7, output=0, feature=0

All the additional keys, including the function keys in case f-lock is 
deactivated, are connected to uhid0, the rest of the keyboard belongs to
ukbd0 (and works as expected).

If I run something like usbhidctl -f uhid0 -la, I get meaningful outputs; 
for example, pressing the "Web/home" key yields

AC_Home=1
No_Event=1
Consumer_Control.0xfe03=1
Consumer_Control.0xfe04=0
Consumer_Control.0xff05=0
Consumer_Control.0xff02=0

releasing it yields

Unassigned=1
No_Event=1
Consumer_Control.0xfe03=1
Consumer_Control.0xfe04=0
Consumer_Control.0xff05=0
Consumer_Control.0xff02=0

All keys generate these events; Consumer_Control 0xfe03 seems to reflect the
current "F-lock" status (and -led), Consumer_control.fe04 seems to reflect the
state of the actual F-lock button. I have no idea what the other controls
are.

Since all keys generate unique events, it should be possible to sucessfully
use usbhidaction. However, many of these keys would generate a "normal" 
keypress on other keyboards, and KDE/Gnome know how to handle those, so I want
to mimick this behaviour. Is there a way to generate keypresses using
usbhidaction? Is there another approach I could try?

Of course, I could try to write a small device driver that would attach
instead of the generic uhid driver, acting like a second wskbd. If they'd both
be in the same mux, the net result would be what I want. There is a Linux
device driver floating out there that does something like this, but I'm not
sure this is the way to go.