kbd scancodes overlaps...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

kbd scancodes overlaps...

Post 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
Laksen
Member
Member
Posts: 140
Joined: Fri Nov 09, 2007 3:30 am
Location: Aalborg, Denmark

Re: kbd scancodes overlaps...

Post by Laksen »

Store the state of special keys(fn, numlock, caps, etc) and use different translation tables for each special key
http://j-software.dk | JPasKernel - My Object Pascal kernel
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: kbd scancodes overlaps...

Post 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.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: kbd scancodes overlaps...

Post 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...
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: kbd scancodes overlaps...

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: kbd scancodes overlaps...

Post 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
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: kbd scancodes overlaps...

Post 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
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: kbd scancodes overlaps...

Post 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:
Post Reply