按箭头键拍两个键盘中断? (int 09h)

时间:2012-03-21 01:17:32

标签: keyboard dos interrupt

我正在学习中断和键盘硬件中断,例如中断9(在dos中)。 我注意到如果我按下一个箭头键(向左,向右,向上,向下),那么将会有两个连续的中断。第一个是'Shift'按钮中断,第二个是我按下的箭头键。

我注意到,因为我重新编写并配置了键盘的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”。 我正在使用罗技Wave键盘。

2 个答案:

答案 0 :(得分:3)

您的numlock已开启。

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

Microsoft的键盘扫描代码为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)的打印件。

答案 1 :(得分: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.

这不完全是你所描述的,但它揭示了相当奇怪的行为。我会说尝试另一个键盘,看看会发生什么。

(我认为这属于评论而非答案,但我看不到评论框......)