m1o*_*1o2 3 keyboard dos interrupt
我正在学习中断和键盘硬件中断,例如中断 9(在 dos 中)。我注意到,如果我按箭头键(左、右、上、下),则会出现两个连续的中断。第一个是“Shift”按钮中断,第二个是我按下的箭头键。
我注意到了这一点,因为我重写并配置了键盘的数字9中断来提示按下按钮的扫描码。
例如,当我按下右箭头键时,我会看到发生了“Shift”按钮中断(在屏幕上显示扫描码 42),然后是我按下的箭头键(右箭头键)还发送一个中断(扫描代码 77)。
我的问题是,为什么会发生这种情况?
我的 int 9 代码:
void interrupt interrupt_9_Implementation{
unsigned char scanCode;
asm{
in al, 60h // read the keyboard input from port 60h ( 96 Decimal ) into al;
mov scanCode, al // save the keyboard input into 'scanCode' varaible
in al, 61h // read 8255 port 61h ( 97 Decimal ) into al
or al, 128 // set the MSB - the keyboard acknowlege signal
out 61h, al // send the keyboard acknowlege signal from al
xor al, 128 // unset the MSB - the keyboard acknowlege signal
out 61h, al // send the keyboard acknowlege signal from al
}
if( 128 > scanCode ){ // if the button is being pressed or being released. if the button is being pressed then the MSb isn't set and therfore it must be smaller than 128
printf("You pressed key assigned scan code = %d\n", scanCode );
if( EscScanCode == scanCode )
EscPressed = _True;
else
printf( "Press any key (almost)\n:" );
}
// send EOI
asm{
mov al, 20h
out 20h, al
}
}
Run Code Online (Sandbox Code Playgroud)
按箭头键(例如右箭头键)后,我会得到:
Press any key (almost)
:You pressed key assigned scan code = 42 // the 'shift' key scan code
Press any key (almost)
:You pressed key assigned scan code = 77 // the right arrow button scan code
Run Code Online (Sandbox Code Playgroud)
到目前为止,只有使用箭头键才会发生这种情况。并且没有按下“Shift”键。我使用的是罗技 Wave 键盘。
你的数字锁已打开。
实际上,您并没有打印收到的所有扫描码。仅当代码小于 128 时才进行打印。但是,扫描代码前面可以添加 0xE0 以指示扩展代码。
微软有一篇关于键盘扫描代码的相当不错的文章,其中有以下描述:
Base Make Base Break
Right Arrow E0 4D E0 CD
...
Num Lock ON Precede Base follow Base Break
Make code with code with
Final Key only E0 2A E0 AA
Run Code Online (Sandbox Code Playgroud)
所以你实际收到的是这个按键序列:
E0 2A E0 4D
Run Code Online (Sandbox Code Playgroud)
由于您的代码不会打印任何高于 128 的内容(0xE0 是 224),因此您只能看到 0x2A (42) 和 0x4D (77) 的打印。
| 归档时间: |
|
| 查看次数: |
2434 次 |
| 最近记录: |