questions about disabling a key using kbfiltr

Hi,

I’m a driver-newbie and wanted to disable a key (+=) on my laptop and map the RShift key to this. I need this for a crazy reason and I know there are multiple ways of doing this and the driver approach is not necessarily the best, but I wanted to try this and changed the kbfiltr.c as follows. My questions are:

  1. Is there a better way of ignoring a keypress apart from using the KbFilter_ServiceCallback function ? Can the IsrHook be used in some way ? What needs to be done if I return with ContinueProcessing as FALSE ?
  2. The following code blocks the += key in most cases. However, whenever I keep pressing the key, a keypress finally escapes the code and is printed. Can someone please tell me what could be wrong with the same.

Thanks,
-AK

VOID
KbFilter_ServiceCallback(
IN PDEVICE_OBJECT DeviceObject,
IN PKEYBOARD_INPUT_DATA InputDataStart,
IN PKEYBOARD_INPUT_DATA InputDataEnd,
IN OUT PULONG InputDataConsumed
)
{
PDEVICE_EXTENSION devExt;
WDFDEVICE hDevice;

PKEYBOARD_INPUT_DATA pTmp1;
PKEYBOARD_INPUT_DATA pTmp2;
PKEYBOARD_INPUT_DATA pEnd;

hDevice = WdfWdmDeviceGetWdfDeviceHandle(DeviceObject);

devExt = FilterGetData(hDevice);

pTmp2 = InputDataStart;
pTmp1 = InputDataStart;
pEnd = InputDataEnd;
while (pTmp2 < pEnd)
{
if (pTmp2->MakeCode != 0x0D)
{
*pTmp1 = *pTmp2;
if (pTmp1->MakeCode == 0x36) // left shift
{
pTmp1->MakeCode = 0x0D;
}
pTmp1++;
}
pTmp2++;
}
pEnd = pTmp1; // pEnd is one more than the end of list

*InputDataConsumed = InputDataEnd - pEnd;
InputDataEnd = pEnd;

(*(PSERVICE_CALLBACK_ROUTINE)(ULONG_PTR) devExt->UpperConnectData.ClassService)(
devExt->UpperConnectData.ClassDeviceObject,
InputDataStart,
InputDataEnd,
InputDataConsumed);

return;
}

To add:
Scan code of += is 0x0D and of RShift is 0x36.

Thanks,
-AK

I have no idea hwat you are doing in the callback, but by passing InputDataStart to the upper service callback you are not skipping over any packets. The general algorithm should be this

PKEYBOARD_INPUT_DATA pCur = InputDataStart

While (pCur < InputDataEnd)
{
ULONG consumed = 0;

If (pCur is a key you want to skip) {
pCur++;
continue;
}
else if (pCur is a key you want to modify) {
modify pCur to whatever you want
}

// indicate one packet at a time
(*(PSERVICE_CALLBACK_ROUTINE)(ULONG_PTR) devExt->UpperConnectData.ClassService)(
devExt->UpperConnectData.ClassDeviceObject,
pCur,
pCur+1,
&consumed);
pCur++;
}

// tell the caller you consumed everything
*InputDataConsumed = (InputDataEnd-InputDataStart);

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Wednesday, March 10, 2010 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] questions about disabling a key using kbfiltr

Hi,

I’m a driver-newbie and wanted to disable a key (+=) on my laptop and map the RShift key to this. I need this for a crazy reason and I know there are multiple ways of doing this and the driver approach is not necessarily the best, but I wanted to try this and changed the kbfiltr.c as follows. My questions are:

  1. Is there a better way of ignoring a keypress apart from using the KbFilter_ServiceCallback function ? Can the IsrHook be used in some way ? What needs to be done if I return with ContinueProcessing as FALSE ?
  2. The following code blocks the += key in most cases. However, whenever I keep pressing the key, a keypress finally escapes the code and is printed. Can someone please tell me what could be wrong with the same.

Thanks,
-AK

VOID
KbFilter_ServiceCallback(
IN PDEVICE_OBJECT DeviceObject,
IN PKEYBOARD_INPUT_DATA InputDataStart,
IN PKEYBOARD_INPUT_DATA InputDataEnd,
IN OUT PULONG InputDataConsumed
)
{
PDEVICE_EXTENSION devExt;
WDFDEVICE hDevice;

PKEYBOARD_INPUT_DATA pTmp1;
PKEYBOARD_INPUT_DATA pTmp2;
PKEYBOARD_INPUT_DATA pEnd;

hDevice = WdfWdmDeviceGetWdfDeviceHandle(DeviceObject);

devExt = FilterGetData(hDevice);

pTmp2 = InputDataStart;
pTmp1 = InputDataStart;
pEnd = InputDataEnd;
while (pTmp2 < pEnd)
{
if (pTmp2->MakeCode != 0x0D)
{
*pTmp1 = *pTmp2;
if (pTmp1->MakeCode == 0x36) // left shift
{
pTmp1->MakeCode = 0x0D;
}
pTmp1++;
}
pTmp2++;
}
pEnd = pTmp1; // pEnd is one more than the end of list

*InputDataConsumed = InputDataEnd - pEnd;
InputDataEnd = pEnd;

(*(PSERVICE_CALLBACK_ROUTINE)(ULONG_PTR) devExt->UpperConnectData.ClassService)(
devExt->UpperConnectData.ClassDeviceObject,
InputDataStart,
InputDataEnd,
InputDataConsumed);

return;
}


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

That is great. I was just trying to modify all the keys received and then call the function in one shot. Is there any estimate on the number of keys received (InputDataEnd - InputDataStart) ? Will there be any sort of a perf issue because I do it key-by-key as mentioned ?

Thanks,
-AK

No estimate on the keys received. On a usb keyboard, it is always one. on a ps2 keyboard, it usually one but could be many more

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Wednesday, March 10, 2010 11:27 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] questions about disabling a key using kbfiltr

That is great. I was just trying to modify all the keys received and then call the function in one shot. Is there any estimate on the number of keys received (InputDataEnd - InputDataStart) ? Will there be any sort of a perf issue because I do it key-by-key as mentioned ?

Thanks,
-AK


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

That makes it clear. I was using a PS2 keyboard and I guess in the case wherein there was 1 key, I was supplying InputDataStart = InputDataEnd in my code with *InputDataConsumed = 0.

I changed the code as you had mentioned and it works fine now. Thanks a lot.

Thanks,
-AK