按箭头键会触发两个键盘中断? (int 09h) [英] pressing on the arrows keys shoots two Keyboard interrupts ? ( int 09h )

查看:135
本文介绍了按箭头键会触发两个键盘中断? (int 09h)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm learning about interrupts and keyboard hardware interrupts such as interrupt 9 ( in dos ). and I noticed that if I press on an arrow key ( left, right, up, down ) then there will be two consecutive interrupts. the first one is the 'Shift' button interrupt and the second is the arrow key that I have pressed.

我注意到,因为我重写并配置了键盘的数字9

I noticed that, since I rewrote and configured the keyboard's number 9 interrupt to prompt the scan code of the pressed button.

例如,当我按向右箭头键时,我会看到 Shift按钮中断有发生(在屏幕上显示扫描代码42),然后我按下的箭头键(向右箭头键)也发送一个中断(扫描代码77)。

for example, when I will press on the right arrow key, I will see that a 'Shift' button interrupt have happend ( shows on the screen the scane code 42 ) and then the arrow key that I have pressed ( the right arrow key ) also send an Interrupt ( scan Code 77 ).

我的问题是,为什么会这样?

My question is, why this is happening ?

我对int 9的代码:

My code for 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
}
}

在我按下箭头键(例如向右箭头键)后,我会得到:

after I press an arrow key ( for example the right arrow key ), I'll get :

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

$到目前为止,b
$ b

仅使用箭头键会发生。并且未按 Shift键。
我正在使用Logitech Wave键盘。

so far It is happening only with the arrows keys. and the 'Shift' isn't pressed. I'm using a Logitech Wave keyboard.

推荐答案

您的数字锁定已打开。

您实际上并不是在打印收到的所有扫描代码。仅当代码小于128时才进行打印。但是,扫描代码可以以0xE0开头,以指示扩展代码。

You're actually not printing all the scancodes you are receiving. You're only printing when the code is less than 128. However, a scan code can be preceded by 0xE0 to indicate an extended code.

Microsoft具有写得很好键盘扫描代码,其描述如下:

Microsoft has a rather nice write-up on keyboard scan codes, which has the following description:

                  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

所以您实际上收到的是以下键序列:

So what you're actually receiving is this key sequence:

E0 2A E0 4D

由于您的代码无法显示128以上的值(0xE0为224) ,您只会看到0x2A(42)和0x4D(77)的照片。

Since your code doesn't print anything above 128 (0xE0 is 224), you only see prints for 0x2A (42) and 0x4D (77).

这篇关于按箭头键会触发两个键盘中断? (int 09h)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆