2012-03-21 77 views
1

我正在学习中断和键盘硬件中断,例如中断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键盘。

回答

0

根据http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html

1.7 Added non-fake shifts 

On my 121-key Nokia Data keyboard there are function keys F1, ..., F24, where F1, ..., F12 
send the expected codes 3b, ..., 58, and F13, ..., F24 send the same codes together with 
the LShift code 2a. Thus, F13 gives 2a 3b on press, and bb aa on release. Similarly, there 
are keys with added LCtrl code 1d. But there are also keys with added fake shifts e0 2a. 

Delorie reports that the "Preh Commander AT" keyboard with additional F11-F22 keys treats 
F11-F20 as Shift-F1..Shift-F10 and F21/F22 as Ctrl-F1/Ctrl-F2; the Eagle PC-2 keyboard 
with F11-F24 keys treats those additional keys in the same way. 

这不正是你的描述,但它揭示了相当古怪的行为的一些情况。我会说尝试另一个键盘,看看会发生什么。

(我想这属于一个评论,而不是一个答案,但我不能看到一个评论框...)

3

你的numlock上。

您实际上并未打印您正在接收的所有扫描码。您只在代码少于128时打印。但是,扫描代码前面可能会有0xE0,表示扩展代码。

微软对键盘扫描码rather nice write-up,其具有如下描述:

    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 

那么你实际上是接受这个按键顺序:

E0 2A E0 4D 

由于你的代码没有按”打印128以上的任何东西(0xE0是224),你只能看到打印的0x2A(42)和0x4D(77)。