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

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(("%s\n",KeyData->Flags? "up":"down"));
    MyPrintKeyStroke((UCHAR)KeyData->MakeCode);

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

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

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(("%s\n",KeyData->Flags? "up":"down"));
    MyPrintKeyStroke((UCHAR)KeyData->MakeCode);

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

C语言:字符串详解

字符串数组
1. 字符串数组的定义与使用

#include "stdio.h"
void main()
{
char abc[15];
printf("input a string:");
scanf("%s",abc);
printf("%s",abc);
} 

当输入是abc124a时输入输出如下表示:
input a string:abc124a
abc124a

当输入是123 abc时输入输出如下表示:
input a string:123 abc
123

Continue Reading
1 8 9 10