Tech Support > Microsoft Windows > Drivers > Keyboard filter driver for the multimedia and power keys on a usb keyboard.
Keyboard filter driver for the multimedia and power keys on a usb keyboard.
Posted by lichtf on January 27th, 2006


Hello all --

I am trying to write a keyboard filter driver that will basically eat
the multimedia and the power keys on a USB keyboard. I used the
kbfiltr sample from the DDK and got it working for a PS/2 keyboard, but
it doesn't work for a USB keyboard.

I've read some other posts and it looks like the multimedia and the
power keys are separate HID collections. If this is true do I need to
write a HID filter driver for these collections?

If this isn't true then what is the best approach to take?

Any help would be greatly appreciated.

Thanks.

Posted by Robert Marquardt on January 27th, 2006


lichtf wrote:
They are indeed separate collections and therefore show up as separate
devices. The multimedia keys are not part of the normal keyboard
handling. They get read by a service and posted as WM_APPCOMMAND
messages to the foreground application. Depending on the return value
for the message handling the keys get suppressed or not.

So if you only want to suppress it for your application then simply
handle WM_APPCOMMAND.

Posted by lichtf on January 27th, 2006


Robert,

Thank you for your response.

I actually need to suppress the keys for all applications, not only my
own.
What I have is a keyboard with the multi-media keys. These keys have
different pictures and labels on them that link to my application. So
I need to prevent these keys from doing what they normally do, by
eating them, and I need to notify my application when they are pressed.
If my application isn't running I still need to eat them. Is there a
way I can do this before the service gets them and posts the
WM_APPCOMMAND?

Another problem is the Power buttons. Even in PS/2 if I ate the keys
they still ended up working, ie. shut down the machine. I found a way
to disable them by using the following code in the
IRP_MJ_DEVICE_CONTROL function on the IOCTL_GET_SYS_BUTTON_CAPS control
code:

ULONG caps;

caps = 0x0;

if(Irp->PendingReturned)
IoMarkIrpPending(Irp);

//
// Get the current value.
//
caps = *(PULONG) Irp->AssociatedIrp.SystemBuffer;
//
// Clear all the bits related to power.
//
caps &= ~(SYS_BUTTON_SLEEP | SYS_BUTTON_POWER | SYS_BUTTON_WAKE);

//
// Set the new value.
//
*(PULONG) Irp->AssociatedIrp.SystemBuffer = caps;

Do you know if there is a way that I can disable the power buttons
functionality, but still get notified about them, for a USB keyboard?

Thanks for the help.

Posted by Doron Holan [MS] on January 28th, 2006


you would filter the appropriate collections based on the hw ID
(HID_DEVICE_SYSTEM_CONSUMER for the app buttons, i don't have the pwr button
offhand). you would install yourself as an upper filter or the service on
both collecitons. for the power button, you should do the same as PS2
(clear out the flags in the ioctl). as for the consumer controls, you would
have to open the collection for exclusive access so that hidserv cannot open
them. once either collection is open, you would continuously polll the
collection by always haveing a read irp pending. what you do with the
results is up to you. see the firefly example for how a HID driver can open
itself up.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"lichtf" <lichtf@gmail.com> wrote in message
news:1138387035.041921.30300@o13g2000cwo.googlegro ups.com...


Posted by Robert Marquardt on January 28th, 2006


AFAIK it is also possible to simply shut down the service for the
multimedia keys. The only drawback is that it is not configurable. The
filter driver could be commanded to stop filtering.

Posted by Barry on January 28th, 2006



"Doron Holan [MS]" <doronh@nospam.microsoft.com> wrote:
How about a lower filter?



Posted by Doron Holan [MS] on January 28th, 2006


the type of filter doesn't matter b/c teh HID PDO is raw and there are no
other drivers attached to it.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Barry" <gubaoqiang@263.net> wrote in message
news:%23ERtfFDJGHA.2628@TK2MSFTNGP15.phx.gbl...


Posted by lichtf on January 30th, 2006


Thank you for your response Doron. It is very helpful.

I haven't had a chance to try your suggestions because I am running
into a problem with actually installing the driver. I started with the
kbfilt sample inf file and tweaked it to try and install the firefly
driver for the HID_DEVICE_SYSTEM_CONSUMER. I made changes to install
to the HID class and for the "correct" device. The installation seemed
to go fine, but it doesn't seem like the driver is actually being used.
I try to output in the DriverEntry function and I never see that on my
debugger. So I'm assuming my installation is incorrect.

One thing I'm not sure about in the inf file is if I need to change
lines like:
Include = MSMOUSE.INF
Needs = HID_Mouse_Inst.NT
or if I can just remove them. Do you know of a sample inf for
installing an upper filter for a HID? Any help would be greatly
appreciated.

Thanks.

Posted by Doron Holan [MS] on January 30th, 2006


you do not reference msmouse.inf in a hid filter, that is for a mouse only.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"lichtf" <lichtf@gmail.com> wrote in message
news:1138638372.275430.307160@f14g2000cwb.googlegr oups.com...


Posted by lichtf on January 30th, 2006


I'm sorry I might not have been clear about what I was asking. I
realize that I don't use the mouse stuff, but I was wondering if I
needed to use something else instead. I think I figured out to include
HIDserv.inf instead.

So now I have it installed, but I get an error that says can't find
device. My driver sees calls to DriverEntry followed immediately by
Unload. I don't understand why nothing else is being called before I
get an unload.

I even tried using a sample filter driver, a very basic one that just
passes things along, from one of Walter Oney's books. This has the
same thing happen.

So the device stops working when I add my filter to it.
Any advice?

Thank you.

Posted by Doron Holan [MS] on January 31st, 2006


i can't tell based on your description what went wrong. i would think that
your driver got installed incorrectly on the device. is the device !'ed out
in device manager?

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"lichtf" <lichtf@gmail.com> wrote in message
news:1138652752.202816.263790@g44g2000cwa.googlegr oups.com...


Posted by lichtf on January 31st, 2006


Yes the device is !'ed out. In the device manager there are 4 entries
in the Hid section. There is a Hid-compliant device, Hid-compliant
consumer control device, and 2 USB Human Interface Device's. My
confusion might be coming from here. My assumption is that the
consumer device is for the multi-media keys, the compliant device is
for the power keys, and the 2 USB HIDs are somehow related to these
other 2.

I tried attaching a filter driver to the USB HIDs and this seems to
work, I haven't tried anything from within the filter driver, but it at
least seems to install and gets called for add device and IRPs. I
tried attaching a filter driver to the other 2 devices and that's where
I got the problem I described above, the device is !'ed out in the
device manager when it has the filter driver attached to it. The error
in the device manager is error 41, can't find the device.