gpt4 book ai didi

keyboard - 按下箭头键会发出两次键盘中断? (诠释 09h)

转载 作者:行者123 更新时间:2023-12-05 01:48:36 28 4
gpt4 key购买 nike

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

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

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 键盘。

最佳答案

您的数字锁定已打开。

您实际上并没有打印您收到的所有扫描码。仅当代码小于 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) 的打印。

关于keyboard - 按下箭头键会发出两次键盘中断? (诠释 09h),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9797361/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com