Page 1 of 1

kbd scancodes overlaps...

Posted: Fri Jul 25, 2008 3:28 pm
by suthers
I have recently been improving my TUI/keyboard driver...
So I was trying to add a num lock system...
But when I got my OS to output the scancodes of the keys I pressed, I found that the NUM lock keys scancode overlap with those of other ones, e.g. 4 on num lock is the same as back arrow...
So I was wondering how are you supposed to deal with this?
Thanks in advance,

Jules

Re: kbd scancodes overlaps...

Posted: Fri Jul 25, 2008 3:40 pm
by Laksen
Store the state of special keys(fn, numlock, caps, etc) and use different translation tables for each special key

Re: kbd scancodes overlaps...

Posted: Fri Jul 25, 2008 3:45 pm
by Korona
Usually the left/right/up/down keys should generate 0xE0 prefixes. IIRC some keyboards might have an internal numlock flag that modifies the scancodes other keys send.
Generally you cannot do anything if two scancodes overlap.

EDIT:
Laksen wrote:Store the state of special keys(fn, numlock, caps, etc) and use different translation tables for each special key
That won't help if the four key and the left arrow key really overlap. If you switch to another translation table the left arrow would generate fours if numlock is active. BTW the fn key does not generate any scancode so the driver cannot keep track of it.

Re: kbd scancodes overlaps...

Posted: Fri Jul 25, 2008 3:48 pm
by suthers
Hmm..., yah I just saw, not much you can do, so to figure out if it's arrows, you have to do a read port with word size....
Thanks,

Jules

edit: added thanks...

Re: kbd scancodes overlaps...

Posted: Sat Jul 26, 2008 5:52 am
by Brendan
Hi,
suthers wrote:Hmm..., yah I just saw, not much you can do, so to figure out if it's arrows, you have to do a read port with word size....
Um, "do a read port with word size"???

If you attempt to do something like "in ax,0x60" then the keyboard controller will probably ignore you, because it's looking for 8-bit read requests on it's bus and not 16-bit read requests. Even if it does respond to 16-bit read requests (which I doubt) you'll get one byte from I/O port 0x60 and another byte from I/O port 0x61, which isn't what you want at all.

You'd need to read the 0xE0 prefix from the keyboard controller, then set a flag (so you know you got the 0xE0 prefix), then wait for the keyboard to send the next byte to the keyboard controller, then get the next byte of the scancode. Then if your "got an 0xE0 prefix" flag is clear you know it was one key, and if your "got an 0xE0 prefix" flag is set you know it was a different key.


Cheers,

Brendan

Re: kbd scancodes overlaps...

Posted: Sat Jul 26, 2008 4:54 pm
by suthers
Ok this is crazy, at the beginning I had a weird bug that I finally figured out, for some reason bochs sent a 0xE0 before AND after pressing an arrow, so I arranged my code to fix it, now I've added a bit more code and I got a HUGE bug, everything quite literally feel to peaces, Just figured out it was because the 0xE0 after wasn't sent after anymore...., which messed up everything...
Can anybody explain this behavior?
Thanks in advance,

Jules

Re: kbd scancodes overlaps...

Posted: Tue Jul 29, 2008 8:10 am
by jal
suthers wrote:Can anybody explain this behavior?
I'm not entirely sure what behaviour you mean, you are not too coherent. The 0xe0 prefix is sent before the press and before the release of the key. Note also that the Numlock scancode (45) does not overlap with the arrow keys, which are 0xe0 + the numpad keys (numeric 8, 4, 6 and 2). See here for a very extensive list of scancodes.


JAL

Re: kbd scancodes overlaps...

Posted: Tue Jul 29, 2008 8:38 am
by suthers
Sorry, that's probably because I've added code to filter out most of the key releases...
My fault.
Thanks,

Jules

edit: changed a bit of text to make it look more coherent :wink: