Page 1 of 1

Some keyboard keys not responding

Posted: Fri Aug 07, 2009 9:45 am
by alethiophile
I am currently in the process of writing a keyboard driver. My current implementation simply listens on IRQ1 and prints the hex value of the scancodes it reads. Code:

Code: Select all

void keyboard_handler(registers_t *regs) {
  if (regs->eax) {}
  u8int key = inportb(0x60);
  printf("%x\n", key);
}
This works fine and as advertised for most keys, but some do not print anything. The numpad keys, other than numlock and enter, do not respond, and neither do the windows-logo keys or the context-menu key. How do I get these keys to respond properly?

Re: Some keyboard keys not responding

Posted: Fri Aug 07, 2009 10:04 am
by salil_bhagurkar
Your code looks perfectly alright. Hence, we need to have a look at the code surrounding your irq handler. The function that calls it, the printf function and inportb. Again, chances are pretty less that there might be trouble in these functions too.

Re: Some keyboard keys not responding

Posted: Fri Aug 07, 2009 10:28 am
by alethiophile
It works for most keys, no? So I would think that a problem with my IRQ handling, my inportb or my printf that only failed to pass the numpad keys would be pretty unlikely.

Re: Some keyboard keys not responding

Posted: Fri Aug 07, 2009 10:36 am
by alethiophile
I have just verified that, in fact, the numpad keys don't work in my host OS either, and instead seem to move the mouse cursor. (?) It might be relevant that on the computer I test on, both keyboard and mouse are plugged into a PS/2 to USB adapter. And when I test it on another computer, whose kb/mouse are connected via PS/2, it works. So I guess this is not a software problem.

Re: Some keyboard keys not responding

Posted: Fri Aug 07, 2009 11:58 am
by kokjo
are you using bochs? that couth be the problem, have you tried on a real machine?

Re: Some keyboard keys not responding

Posted: Fri Aug 07, 2009 12:29 pm
by Combuster
kokjo wrote:have you tried on a real machine?
And when I test it on another computer, whose kb/mouse are connected via PS/2, it works.
Would you mind reading before posting a reply?
only failed to pass the numpad keys
Interesting that those are codes normally prefixed with e0 - I wonder if the combination of that and USB might have something to do with it, but I don't see anything in the shown code that might explain that behavior (please post the full code)

Re: Some keyboard keys not responding

Posted: Fri Aug 07, 2009 11:37 pm
by alethiophile
The numpad keys are fixed--turns out it was some obscure X setting that kidnapped the numpad keys for mouseless control of the cursor. None of the 'Windows-specific' keys work, even on hardware.