我正在學習中斷和鍵盤硬件中斷,例如中斷9(在dos中)。 我注意到,如果我按下箭頭鍵(左,右,上,下),則會出現兩個連續的中斷。第一個是'Shift'按鈕中斷,第二個是我按下的箭頭鍵。按下箭頭鍵拍攝兩個鍵盤中斷? (int 09h)
我注意到,因爲我重寫並配置了鍵盤的9號中斷來提示按下按鈕的掃描碼。例如,當我按下右箭頭鍵時,我會看到發生了'Shift'按鈕中斷(在屏幕上顯示了scane代碼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
}
}
後,我按箭頭鍵(例如右箭頭鍵),我會得到:
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
到目前爲止,這是唯一的發生用箭頭鍵。而'Shift'沒有被按下。 我使用的是Logitech Wave鍵盤。