Tech Support > Microsoft Windows > Drivers > Re: Help me about USB keyboard upper filter driver.
Re: Help me about USB keyboard upper filter driver.
Posted by Doron Holan [MS] on July 22nd, 2004


on a (usb) hid device, the power and the media keys are in separate top
level collections and are enumerated as separate devices. you can put a
filter on either of these and change the usages, but only with the usage
page. ie you can make the media keys behave like other media keys, but you
cannot make a media key behave like a keyboard press (for instance mapping
volume up to the letter 'a' is not possible).

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.


"Deauty Fan" <zkfm@vip.163.com> wrote in message
news:uGHz11wbEHA.1132@TK2MSFTNGP10.phx.gbl...


Posted by Deauty Fan on July 22nd, 2004


Thank you very much.
And I want to know how to write the filter driver for media keys and also
how to install it,will you tell me?

"Doron Holan [MS]" <doronh@nospam.microsoft.com> дÈëÏûÏ¢ÐÂÎÅ
:O3ju#E6bEHA.4032@TK2MSFTNGP11.phx.gbl...


Posted by Doron Holan [MS] on July 22nd, 2004


to install it, you need to look at the PDO and devstack for the media keys
and find their hw and compatible IDs. for instance on my MSFT natural
keyboard, there is the following device hierarchy

Microsoft Natural Keyboard Pro
+ Microsoft Natural Keyboard Pro Hot Keys
+ HID-compliant device (this is the power key)
+ Microsoft Naturla Keyboard Pro Consumer Controls (these are the
media keys) <-- this is the one you want

you then can write a filter on top of the PDO. your filter will trap read
requests (and perhaps get feature ioctls, i can't remember) and will have to
use the HidP_Xxx routines (link against hidparse.dll) to parse the results.
HidP is the kmode equivalent of the HidD_xxx routines.

Now, with all that said, you may not need a driver at all. What type of
mapping do you want to do ? i think that you should investigate a low level
keyboard hook (see SetWindowsHookEx) and see if that does what you want. i
would always use a user mode solution of kernel mode one if it is available.

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.


"Deauty Fan" <zkfm@vip.163.com> wrote in message
news:%23NhCJ$6bEHA.716@TK2MSFTNGP11.phx.gbl...


Posted by Deauty Fan on July 23rd, 2004


Thank you.

May be,I will try SetWindowsHookEx on. I
know more about keyboard hook than writing driver.


Posted by Deauty Fan on July 23rd, 2004


Sir ,may you allow me to ask you a new question?

I wrote a APP to access the USB keyboard directly.I successed to do that
in Win98,but I don't know why can't in WinXP,someone said that is because
keyboard is only system accessible in WinXp.
Is it right?
If it is right, how to change my APP code to access the keyboard.

Thanks,
Deauty


Posted by Doron Holan [MS] on July 23rd, 2004


for media keys, i think you need a shell hook, not a keyboard hook. You
should read the msdn docs on the hook types and see which is appropriate.

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.


"Deauty Fan" <zkfm@vip.163.com> wrote in message
news:OIiFrgJcEHA.4032@TK2MSFTNGP11.phx.gbl...


Posted by Doron Holan [MS] on July 23rd, 2004


that is correct, the system opens the device exclusively. you cannot change
your app to access the keyboad w/out a driver.

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.


"Deauty Fan" <zkfm@vip.163.com> wrote in message
news:%23xccfwJcEHA.212@TK2MSFTNGP12.phx.gbl...


Posted by Deauty Fan on July 24th, 2004


Thank you sir,
I don't know why but I can access the USB keyboard in my APP now.I use
If I don't change my old 98 edition APP,error handle will return,first I
don't know where error occur,after I test,I remove a line in 98 edition ,

CloseHandle(PnPHandle);

After remove this line ,everything work correctly,including get key code,why
must remove this line?and why not in 98?Is it the system opens the device
exclusively on XP?



BOOL OpenUserKeyboard ()
{
struct _GUID HidGuid;
SP_INTERFACE_DEVICE_DATA DeviceInterfaceData;

struct
{
DWORD cbSize;
char DevicePath[256];

} FunctionClassDeviceData;

int Success,
HidDevice;

BOOL OpennedSys;
HANDLE PnPHandle;

unsigned long BytesReturned;
struct _HIDD_ATTRIBUTES Attributes;
struct _HIDP_PREPARSED_DATA *PreparsedData;
struct _HIDP_CAPS Capabilities;

// First, get my class identifier
HidD_GetHidGuid(&HidGuid);
// Get a handle for the Plug and Play node and request currently active HID
devices
PnPHandle =
SetupDiGetClassDevs(&HidGuid,0,0,DIGCF_PRESENT|DIG CF_INTERFACEDEVICE);

if ((int)PnPHandle == -1)
return FALSE;

OpennedSys = false;
// Lets look for a maximum of 40 HID devices
for (HidDevice = 0; (HidDevice < 40) && !OpennedSys; HidDevice++)
{
// Initialize our Data
DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA ); // Length
of data structure in bytes

// Is there a HID device at this table entry
Success = SetupDiEnumDeviceInterfaces(PnPHandle, 0, &HidGuid, HidDevice,
&DeviceInterfaceData);
if (Success == 1)
{
// There is a device here, get it's name
FunctionClassDeviceData.cbSize = 5;
ZeroMemory(FunctionClassDeviceData.DevicePath,size of(char)*256);

Success = SetupDiGetDeviceInterfaceDetail(PnPHandle,
&DeviceInterfaceData,
PSP_INTERFACE_DEVICE_DETAIL_DATA(&FunctionClassDev iceData), 256,
&BytesReturned, 0);

if (Success == 0)
return FALSE;

// Can now open this HID device
HidHandleSys = CreateFile(FunctionClassDeviceData.DevicePath,
GENERIC_WRITE|GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);

// Is it OUR HID device?
HidD_GetAttributes(HidHandleSys, &Attributes);

if ((Attributes.VendorID == 0x62A) && (Attributes.ProductID == 0x101))
{
if (!HidD_GetPreparsedData(HidHandleSys, &PreparsedData))
return FALSE;

if (!HidP_GetCaps(PreparsedData, &Capabilities))
return FALSE;

if ((Capabilities.UsagePage == 9) && (Capabilities.Usage == 1))
OpennedSys = true;
else
CloseHandle(HidHandleSys);
HidD_FreePreparsedData(PreparsedData);
}
}
}

///
//// CloseHandle(PnPHandle); must remove this line
///

bCommandEnable= DriverConnected =OpennedSys;
return OpennedSys;
}


Posted by Doron Holan [MS] on July 24th, 2004


98 and NT are completely different in this regard, this doesn't surprise me.
As for why it works, I don't know the answer to that.

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.


"Deauty Fan" <zkfm@vip.163.com> wrote in message
news:%23tx59bRcEHA.2388@TK2MSFTNGP11.phx.gbl...


Posted by Deauty Fan on July 25th, 2004


Thank you very much.