Keyboard filter driver for the multimedia and power keys on a usb keyboard.

Discussion in 'Windows Vista Drivers' started by lichtf, Jan 27, 2006.

  1. lichtf

    lichtf Guest

    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.

    lichtf, Jan 27, 2006
    1. Advertisements

  2. 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.
    Robert Marquardt, Jan 27, 2006
    1. Advertisements

  3. lichtf

    lichtf Guest


    Thank you for your response.

    I actually need to suppress the keys for all applications, not only my
    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

    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

    ULONG caps;

    caps = 0x0;


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

    // 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.
    lichtf, Jan 27, 2006
  4. 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.

    Doron Holan [MS], Jan 28, 2006
  5. 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.
    Robert Marquardt, Jan 28, 2006
  6. lichtf

    Barry Guest

    How about a lower filter?
    Barry, Jan 28, 2006
  7. the type of filter doesn't matter b/c teh HID PDO is raw and there are no
    other drivers attached to it.


    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.
    Doron Holan [MS], Jan 28, 2006
  8. lichtf

    lichtf Guest

    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

    lichtf, Jan 30, 2006
  9. you do not reference msmouse.inf in a hid filter, that is for a mouse only.

    Doron Holan [MS], Jan 30, 2006
  10. lichtf

    lichtf Guest

    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.
    lichtf, Jan 30, 2006
  11. 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?

    Doron Holan [MS], Jan 31, 2006
  12. lichtf

    lichtf Guest

    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.
    lichtf, Jan 31, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.