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
kbd scancodes overlaps...
Re: kbd scancodes overlaps...
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
Re: kbd scancodes overlaps...
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:
Generally you cannot do anything if two scancodes overlap.
EDIT:
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.Laksen wrote:Store the state of special keys(fn, numlock, caps, etc) and use different translation tables for each special key
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].
Re: kbd scancodes overlaps...
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...
Thanks,
Jules
edit: added thanks...
Re: kbd scancodes overlaps...
Hi,
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
Um, "do a read port with word size"???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....
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.
Re: kbd scancodes overlaps...
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
Can anybody explain this behavior?
Thanks in advance,
Jules
Re: kbd scancodes overlaps...
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.suthers wrote:Can anybody explain this behavior?
JAL
Re: kbd scancodes overlaps...
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
My fault.
Thanks,
Jules
edit: changed a bit of text to make it look more coherent


