键盘过滤驱动勘误《寒江独钓》

2023-02-28 10:20:34 浏览数 (1)

代码语言:javascript复制
Keydata=Irp->AssociatedIrp.SystemBuffer;
numKeys=Irp->IoStatus.Information / Sizeof(KEYBOARD_INPUT_DATA);
for ( i=0;i<numKeys;i  )
{
    DbgPrint(("numKeys : %d ",numKeys));
    DbgPrint(("Scan code : %x ",KeyData->MakeCode));
    DbgPrint(("%sn",KeyData->Flags? "up":"down"));
    MyPrintKeyStroke((UCHAR)KeyData->MakeCode);

    if (KeyData->MakeCode==CAPS_LOCK)
    {
        KeyData->MakeCode=LCONTROL;
    }
}

以上是书上的源代码,整个循环体只遍历了第一个结构体,后面的并没有进行操作,虽然有个循环但是并没有什么实质的作用,正确的遍历代码应该是下面的样子。程序代码所在页面Page-73

代码语言:javascript复制
Keydata=Irp->AssociatedIrp.SystemBuffer;
numKeys=Irp->IoStatus.Information / Sizeof(KEYBOARD_INPUT_DATA);
for ( i=0;i<numKeys;i  ,numKeys  )
{
    DbgPrint(("numKeys : %d ",numKeys));
    DbgPrint(("Scan code : %x ",KeyData->MakeCode));
    DbgPrint(("%sn",KeyData->Flags? "up":"down"));
    MyPrintKeyStroke((UCHAR)KeyData->MakeCode);

    if (KeyData->MakeCode==CAPS_LOCK)
    {
        KeyData->MakeCode=LCONTROL;
    }
}

0 人点赞