Keyboard nerdery: Difference between revisions

From Helpful
Jump to navigation Jump to search
mNo edit summary
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{#addbodyclass:tag_tech}}


==How most systems deal with varying keyboards (an introduction to the wild world that is keyboard input)==


=="How do I type the euro sign on my keyboard" (and an introduction to the wild world that is keyboard input)==
<!--
{{stub}}
 
Perhaps the most steering piece of information is that no matter what the characters on the physical keyboard are,
the keyboard does not send those specific characters.
 
It's also not quite "second row, fifth key", but this is ''somewhat'' closer to the truth.
 
 
The practical way we have solved this
 
 
 
Slightly longer version:
 
: the OS or the keyboard doesn't know about that bit of paint on the keycap.
: A specific OS, when told you are in a specific EU country, it will process some additional input sequences -- in this case Ctrl-Alt-5.
: If (like me) you set your keyboard to US regardless, then ''you will not get those''


<!--


If you're in the EU, your keyboard probably has a € as a third symbol on the 5, the E, or the 4{{verify}}.


How do you even use that?


...turns out this is far from obvious, so a better question that you'ld think.






'''For context'''
'''Longer version - For context'''


In general, there is in fact quite a disconnect between what's printed on the key and what they computer receives,
In general, there is in fact quite a disconnect between what's printed on the key and what they computer receives,
'''or''' to what precisely it does with it.
'''and''' to what precisely it does with it.


The keyboard sends just one code for that key - it really doesn't care what people have written on top.
The keyboard sends just one code for that key - it really doesn't care what people have written on top.
Line 44: Line 58:
In fact, different OSes model keyboard and language in different ways, so the way to configure it will also vary
In fact, different OSes model keyboard and language in different ways, so the way to configure it will also vary


-->
==="How do I type the euro sign on my keyboard" ===
{{stub}}
If you're in the EU, your keyboard probably has a € as a third symbol on the 5, the E, or the 4{{verify}}.
How do you even use that?


It turns out to be a much better question that you'ld think, in that this is far from obvious.
tl;dr:
* if you set the keyboard to a language that support is, there will be a key combo
:: it might be {{keyhold|Ctrl}}{{keyhold|Alt}}{{key|5}}
:: it might be {{keyhold|Option}}{{key|2}} or {{keyhold|Option}}{{keyhold|Shift}}{{key|2}}
:: it might be something else
<!--


'''Windows only'''
'''Windows only'''
Line 73: Line 109:
When you have a lot of buttons, you can give each one their own pair of wires and input,  
When you have a lot of buttons, you can give each one their own pair of wires and input,  
but it is much more economical to use fewer wires.
but it is much more economical to use fewer wires.


This implies there is a limit of buttons that you can press at the same time before it becomes ambiguous.  
This implies there is a limit of buttons that you can press at the same time before it becomes ambiguous.  
When it does, a hardware implementation has the option to  
When it does, a hardware implementation has the option to  
: '''ghost''' - keys are registered unrelated to the ones you pressed
* '''ghost''' - keys are registered unrelated to the ones you pressed, or
: '''block''' - not emitting some of the keys you pressed
* '''block''' - not emitting some of the keys you pressed


Most controllers, when they run into this limit, will block rather than ghost -- it's the safer option that also leads to fewer angry helpdesk calls.
Most controllers, when they run into this limit, will block rather than ghost -- it's the safer option that also leads to fewer angry helpdesk calls.




As a result, '''key rollover''' refers to the number of keys that can be registered simultaneously without either ghosting or blocking.


'''Key rollover''' refers to the number of keys that can be registered simultaneously without either ghosting or blocking.
Not the best case or average, the worst case - the thing you can ''guarantee''.
 
...regardless of which keys they are - so basically limited by the ''worst'' case you can find, not the best or average.
 
As that suggests, that worst-case number is not the maximum number of simultaneous keys you can get out ''if you get to choose''.  




Limits happen within clusters.
Limits happen within clusters.


* Take the cheap keyboard I'm typing this on.  
* Take the cheap keyboard I'm typing this on.  
: I can press all of ASDFGHJKL at once - that's 9 right there.
: I can press all of ASDFGHJKL at once - that's 9 right there.
: If I hold down Q and A, I can't press E. This keyboard is in fact 2-key rollover (2KRO).
: Yet if I hold down Q and A, I can't press E. This keyboard is in fact 2-key rollover (2KRO).


* The same keyboard, within QWEASD
* The same keyboard, within QWEASD
Line 104: Line 138:


* At the same time, I have zero conflicts within WASDFGR (and I can add ''either'' of Q or E, but not both).
* At the same time, I have zero conflicts within WASDFGR (and I can add ''either'' of Q or E, but not both).
 
: Or, in fact, within WASDFGR, Shift, Control, Space, Tab - that's 11 keys.
* Or, in fact, within WASDFGR, Shift, Control, Space, Tab - that's 11 keys.
: In fact I can get a rather specific combination of 13 keys (probably a few more, but it's very uncomfortable on the hands).
: In fact I can get a rather specific combination of 13 keys (possibly more, but it's very uncomfortable on the hands).




I'm assuming this is not uncommon in 2KRO keyboards,
I'm assuming this is not uncommon in 2KRO keyboards,
because game designers tend to put a ''lot'' of actions on those ten keys, and sorta-exclusive things on Q and E.
because game designers tend to put a ''lot'' of actions on those ten keys, and sorta-exclusive things on Q and E.
Due to the way gamers land on WASD and use one finger to do the Q and E, you may never even have noticed this even playing on cheap 2KRO keyboards.


 
But - another cheap keyboard I have, also 2KRO, has a lot more conflicts within that same sorta-gaming set.
But - another cheap keyboard I have, also 2KRO, actually has a ''lot'' of conflicts within that same sorta-gaming set.
Still mostly fine in most games, but enough to bother me.
Still mostly fine in most games, but enough to bother me.


This is one reason that 2KRO is a crapshoot for gaming (sometimes perfectly fine, sometimes bad),
and 6KRO is the "''basically'' never have to worry about it" choice. (well, NKRO is, where every key is scanned independently, but 6 is practically almost impossible to find problems on)


This is one reason that 2KRO is a crapshoot for gaming, and 6KRO is basically the "never have to worry about it" choice.




 
===Why limits?===
'''Why limits?'''


The difference between the rollover number,  
The difference between the rollover number,  
Line 130: Line 163:




====Wiring====


'''Wiring'''
Sure, you could wire all ~100ish keys separately, but that's so much wire, and difficult to route.
Sure, you could wire all ~100ish keys separately, but that's so much wire, and difficult to route.


Line 144: Line 177:
Instead, you can wire it in a way that is conceptually very similar to a {{imagesearch|switch matrix ghosting|switch matrix}} -- and probably best introduced that way.  
Instead, you can wire it in a way that is conceptually very similar to a {{imagesearch|switch matrix ghosting|switch matrix}} -- and probably best introduced that way.  


This multiplexes the wires, in a way where keys share wires.  
This shares wires (look at multiplexing).
Pressing any one is unambiguous,
Pressing any one is unambiguous, whereas ''specific'' combinations may be ambiguous or not.
whereas ''specific'' combinations may be ambiguous or not.




When ambiguous, the controller has a choice - it can send out extra keypresses for things you didn't press,  
When ambiguous, the controller has a choice - it can send out extra keypresses for things you didn't press,  
or it can say 'this is messy, I will send out nothing', which is clearly the safer choice.  
or it can say 'this is messy, I will send out nothing', which is clearly the safer choice. (again, ghosting and blocking)


Because of some practical details, it turns out that 2KRO is fairly simple to do, while more than that gets more involved.
Because of some practical details, it turns out that 2KRO is fairly simple to do, while more than that gets more involved.
Line 156: Line 188:




'''Communication'''
====Communication====


The way it's communicated can also be a limitation.  
The way it's communicated can also be a limitation.  
Line 165: Line 197:
For example, USB has a simplified variant of keyboard protocol, with fixed size packets, with one byte reserved for modifier keys, and space for six scancodes.
For example, USB has a simplified variant of keyboard protocol, with fixed size packets, with one byte reserved for modifier keys, and space for six scancodes.


This protocol is used during the text-mode part of PC boot, when the BIOS rather than the real OS is in control,
This protocol is used during the text-mode part of PC boot, when the BIOS is still in control
because this is one of a few reasons the BIOS's USB stack can be a lot simpler.
because there is no OS in the picture yet.
 
The BIOS's USB stack can be a lot simpler when it only has to deal with this simple variant.




Line 173: Line 207:
Yes, this simplified format is 6KRO, but only during boot.
Yes, this simplified format is 6KRO, but only during boot.


And yes, many cheap keyboards implement only this protocol, because it's enough, particularly if on the mechanical side it's no better than 6KRO anyway.
And yes, many cheap keyboards implement only this protocol, because it's enough.
: More so if its key wiring is not much better than 6KRO anyway.
 




But a full USB implementation includes all of USB HID spec, which can basically already work around that problem, e.g.  
But a full USB implementation includes all of USB HID spec, which can basically already work around that problem, e.g.  
* by switching to a device-specific driver (it would only be 6KRO during early boot, when it ''really'' doesn't matter).
: by switching to a device-specific driver (it would only be 6KRO during early boot, when it ''really'' doesn't matter).
* by reporting as multiple completely standard 6KRO keyboards
: by reporting as multiple completely standard 6KRO keyboards


Some NKRO keyboards do the latter.  
Some NKRO keyboards do the latter.  
But many seem to prefer the driver way, more so when there's also colorful blinky LEDs to control{{verify}}.
But many seem to prefer the driver way, more so when there's also colorful blinky LEDs to control{{verify}}.


Line 192: Line 229:




'''So how much do you need?'''
===So how much do you need?===


2-key rollover might be good enough for typing, because you tend to hit only one or two keys at a time<!--,
2-key rollover might be good enough for typing, because you tend to hit only one or two keys at a time<!--,
Line 229: Line 266:


The theory is that  
The theory is that  
* USB2 polls that standard keyboards themselves request to be rate-limited to 125Hz, so what is sent is 1 to 8ms late
* USB2 polls that standard keyboards themselves request to be rate-limited to 125Hz, so what is sent is 1ms to 8ms later than the physical press
* PS2 is handled by a hardware interrupt, so you are literally halting your CPU with every every keypress to make it run a 'read out my value' handler.
* PS2 is handled by a hardware interrupt, so you are literally halting your CPU with every every keypress to make it run a 'read out my value' handler.


Line 237: Line 274:


Assuming it's true, then the ''maximum'' difference between 125Hz and 1000Hz is 7ms or so, the '''''average''''' difference between 125Hz and 1000Hz is at most 3.5ms (~4ms avg and ~0.5 avg, assuming no overheads, which there are).
Assuming it's true, then the ''maximum'' difference between 125Hz and 1000Hz is 7ms or so, the '''''average''''' difference between 125Hz and 1000Hz is at most 3.5ms (~4ms avg and ~0.5 avg, assuming no overheads, which there are).




Line 242: Line 280:
"You're suggesting it's not true?"
"You're suggesting it's not true?"


USB2 devices waiting for the PC to poll them is absolutely a thing.


USB2 devices waiting for the PC to poll them is absolutely a thing.  
That it's 125Hz for most keyboards is also true.  


That it's 125Hz for most keyboards is also true. So yeah, there's a 4ms average, 8ms maximum delay.
So yeah, there's a 4ms average, 8ms maximum delay.
: Gamer keyboards will often ask for 1000Hz updates, which means this data transfer can happen a few milliseconds earlier.
: Gamer keyboards will often ask for 1000Hz updates, which means this data transfer can happen a few milliseconds earlier.


Line 252: Line 291:
The PS/2 part is ''partially'' overstated.
The PS/2 part is ''partially'' overstated.


All the gamers say "it's interrupts" but the idea that they keyboard interrupts the main processor was very early days, and would now be bad design.
All the gamers say "it's interrupts" but the idea that they keyboard interrupts the main processor was very early days,  
and would now be terrible design leading to a lot of issues.
You are talking to a peripheral, which has been sitting on the southbridge for a long time.  
You are talking to a peripheral, which has been sitting on the southbridge for a long time.  


Line 260: Line 300:
means this is low with less variation.
means this is low with less variation.


I'm not 100% on how the OS pushes this event towards an app.  
I'm not 100% on how the OS pushes this event towards an app.
(which matters to me wanting to measure this some day)
(which matters to me wanting to measure this some day)


Line 283: Line 323:




The thing is that the above argument focuses on just one part of this.
The crux here is that the USB-versus-PS/2 argument focuses only just a small part of this - steps 5 to 6.
The above USB-versus-PS/2 argument focuses only on steps 5 to 6, and ''completely ignores'' things like:
And it ''completely ignores'' things like:
* the physical travel of the key before it will register (~3ms)
* the physical travel of the key before it will register (~3ms)
* the matrix-scanning nature of the readout (3..30ms{{verify}})
* the matrix-scanning nature of the readout (3..30ms{{verify}})
* the debouncing necessary - assume it's at least 5ms, and often not much more than 25ms
* the debouncing necessary - assume it's within between 5ms..25ms


which happen in the first three steps and will be present ''regardless'' of whether you then talk PS/2 opr USB.
These will happen in the first three steps and will be present before the interconnect enters into it,
so happen ''regardless'' of whether you then talk PS/2 or USB.
If it's a gamer keyboard more attention will have been paid, but you can only improve them so much. Physics is in the way.
If it's a gamer keyboard more attention will have been paid, but you can only improve them so much. Physics is in the way.
 
 
Point is, ''maybe'' you save a few ms overall, on top of a few multiples of that that you cannot avoid,
or absolutely can change but aren't even thinking about.
 


[https://www.youtube.com/watch?v=eEswl6kZq5k This] mentioned below takes a much more pragmatic approach and measures 2-to-6,
[https://www.youtube.com/watch?v=eEswl6kZq5k This] mentioned below takes a much more pragmatic approach and measures 2-to-6,
Line 299: Line 344:
And as is remarked, the gamer end pushes down the first steps ''maybe'' 10ms ''regardless of how it is transferred''.
And as is remarked, the gamer end pushes down the first steps ''maybe'' 10ms ''regardless of how it is transferred''.


And I trust that the transfer part was order of 1ms.
And I trust that the transfer part was order of 1ms either way.





Latest revision as of 16:22, 20 April 2024

How most systems deal with varying keyboards (an introduction to the wild world that is keyboard input)

"How do I type the euro sign on my keyboard"

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.


If you're in the EU, your keyboard probably has a € as a third symbol on the 5, the E, or the 4(verify).

How do you even use that?

It turns out to be a much better question that you'ld think, in that this is far from obvious.


tl;dr:

  • if you set the keyboard to a language that support is, there will be a key combo
it might be CtrlAlt5
it might be Option2 or OptionShift2
it might be something else


Key rollover

When you have a lot of buttons, you can give each one their own pair of wires and input, but it is much more economical to use fewer wires.


This implies there is a limit of buttons that you can press at the same time before it becomes ambiguous.

When it does, a hardware implementation has the option to

  • ghost - keys are registered unrelated to the ones you pressed, or
  • block - not emitting some of the keys you pressed

Most controllers, when they run into this limit, will block rather than ghost -- it's the safer option that also leads to fewer angry helpdesk calls.


As a result, key rollover refers to the number of keys that can be registered simultaneously without either ghosting or blocking.

Not the best case or average, the worst case - the thing you can guarantee.


Limits happen within clusters.

  • Take the cheap keyboard I'm typing this on.
I can press all of ASDFGHJKL at once - that's 9 right there.
Yet if I hold down Q and A, I can't press E. This keyboard is in fact 2-key rollover (2KRO).
  • The same keyboard, within QWEASD
most combinations of 3 are fine
many combinations of 4 are fine
a few of 5 are fine
In fact, all problems seem to happen when pressing Q and E.
  • At the same time, I have zero conflicts within WASDFGR (and I can add either of Q or E, but not both).
Or, in fact, within WASDFGR, Shift, Control, Space, Tab - that's 11 keys.
In fact I can get a rather specific combination of 13 keys (probably a few more, but it's very uncomfortable on the hands).


I'm assuming this is not uncommon in 2KRO keyboards, because game designers tend to put a lot of actions on those ten keys, and sorta-exclusive things on Q and E. Due to the way gamers land on WASD and use one finger to do the Q and E, you may never even have noticed this even playing on cheap 2KRO keyboards.

But - another cheap keyboard I have, also 2KRO, has a lot more conflicts within that same sorta-gaming set. Still mostly fine in most games, but enough to bother me.

This is one reason that 2KRO is a crapshoot for gaming (sometimes perfectly fine, sometimes bad), and 6KRO is the "basically never have to worry about it" choice. (well, NKRO is, where every key is scanned independently, but 6 is practically almost impossible to find problems on)


Why limits?

The difference between the rollover number, and the maximum, and the fact that specific keys will and won't work together, often comes mainly from the way it's wired, and to a lesser degree from how it communicates.


Wiring

Sure, you could wire all ~100ish keys separately, but that's so much wire, and difficult to route.

It's not even that wire costs much more. It's that routing that many wires around each other is somewhere between 'really messy' and 'impossible', depending on further constraints.


Instead, you can wire it in a way that is conceptually very similar to a switch matrix -- and probably best introduced that way.

This shares wires (look at multiplexing). Pressing any one is unambiguous, whereas specific combinations may be ambiguous or not.


When ambiguous, the controller has a choice - it can send out extra keypresses for things you didn't press, or it can say 'this is messy, I will send out nothing', which is clearly the safer choice. (again, ghosting and blocking)

Because of some practical details, it turns out that 2KRO is fairly simple to do, while more than that gets more involved.


Communication

The way it's communicated can also be a limitation.

Yet there are some silly (but very persistent) myths around this.


For example, USB has a simplified variant of keyboard protocol, with fixed size packets, with one byte reserved for modifier keys, and space for six scancodes.

This protocol is used during the text-mode part of PC boot, when the BIOS is still in control because there is no OS in the picture yet.

The BIOS's USB stack can be a lot simpler when it only has to deal with this simple variant.


This has led to the myth that USB is only ever 6KRO.

Yes, this simplified format is 6KRO, but only during boot.

And yes, many cheap keyboards implement only this protocol, because it's enough.

More so if its key wiring is not much better than 6KRO anyway.


But a full USB implementation includes all of USB HID spec, which can basically already work around that problem, e.g.

by switching to a device-specific driver (it would only be 6KRO during early boot, when it really doesn't matter).
by reporting as multiple completely standard 6KRO keyboards

Some NKRO keyboards do the latter.

But many seem to prefer the driver way, more so when there's also colorful blinky LEDs to control(verify).


An even sillier myth is that because PS2 didn't have this problem (it sends a packet for each event), using one of those USB-to-PS2 adapters will make it it NKRO.

This makes no sense whatsoever, for multiple reasons. But the main one is that if your OS doesn't know how to talk to your NKRO keyboard, then neither will a generic adapter. And what it talks after that happens is irrelevant.



So how much do you need?

2-key rollover might be good enough for typing, because you tend to hit only one or two keys at a time.


Gamers will often be holding down four or five keys, so 2-key rollover isn't great,

sure it may work - I never noticed either of my 2KRO keyboard were that before.
but 2 is the only guarantee you have
The better one has no conflicts within the most typical gaming keys - involving more keys than I have fingers.
The worse one is still mostly fine within the keys you would most typically hold together in games.


But that difference also illustrates that you'll never know exactly which combinations of keys aren't going to work.

So if you want a guarantee, you look for designs that guarantee it.

Most gamers will be perfectly fine fine with 6KRO, because the specific combinations of 7 keys you can't hit are even harder to hit (certainly with one hand), and even easier to avoid by design.

NKRO then is overkill - but also the simplest way to never have to think about it again.


See also:

Keyboard response time

PS/2 protocol

Keycodes