1

我已经编辑了 WDK kbfiltr.c回调例程来拦截Esc密钥并将其替换为“E”。
它的工作原理是它总是用 2 个“E”替换它。
所以按Esc会输出'ee'。这是代码:

{
PKEYBOARD_INPUT_DATA pCur = InputDataStart; 

PDEVICE_EXTENSION   devExt;
WDFDEVICE   hDevice;

hDevice = WdfWdmDeviceGetWdfDeviceHandle(DeviceObject);
devExt = FilterGetData(hDevice);

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

if (pCur->MakeCode == 0x01) {//Esc
pCur->MakeCode = 0x12; //E
}
else{
pCur++;
continue;
}

// 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);

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

有人知道我在做什么错吗?

4

1 回答 1

1

我认为这是编码错误。如下更改代码似乎可以使其正常工作。

    {
PKEYBOARD_INPUT_DATA pCur = InputDataStart; 

PDEVICE_EXTENSION   devExt;
WDFDEVICE   hDevice;

hDevice = WdfWdmDeviceGetWdfDeviceHandle(DeviceObject);
devExt = FilterGetData(hDevice);

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

if (pCur->MakeCode == 0x01) {//Esc
pCur->MakeCode = 0x12; //E
}

// 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);

}
于 2013-04-16T11:46:24.390 回答