2013-04-12 22 views
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); 
} 

任何人都知道我做錯了嗎?

+1

這只是一個猜測,但你得到一個用於按鍵和一個用於密鑰發佈? – Vicky

+0

我不這麼認爲,因爲它似乎是通過按鍵來完成的,並且一直持有按鍵 - 就像正常輸入時一樣。 – user2272952

+1

看看這裏的定義:http://msdn.microsoft.com/en-gb/library/windows/hardware/ff542337%28v=vs.85%29.aspx我認爲你需要檢查標誌看看無論你有「makecode」還是「breakcode」。 – Vicky

回答

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

}