Reputation: 1629
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.
I noticed that, since I rewrote and configured the keyboard's number 9 interrupt to prompt the scan code of the pressed button.
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 ?
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
so far It is happening only with the arrows keys. and the 'Shift' isn't pressed. I'm using a Logitech Wave keyboard.
Upvotes: 3
Views: 2545
Reputation: 17866
Your numlock is on.
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 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
Since your code doesn't print anything above 128 (0xE0 is 224), you only see prints for 0x2A (42) and 0x4D (77).
Upvotes: 5
Reputation: 2598
According to 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.
This isn't exactly what you describe, but it sheds some light on the rather odd behaviour. I'd say try another keyboard and see what happens.
(I think this belongs as a comment rather than an answer, but I can't see a comment box...)
Upvotes: 1