Keyboard nerdery: Difference between revisions
m (→Key rollover) |
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)== | |||
<!-- | |||
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'' | |||
'''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, | ||
''' | '''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, 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. | 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. | 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. | ||
: | : 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. | |||
: 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 ( | |||
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, | |||
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) | |||
===Why limits?=== | |||
The difference between the rollover number, | The difference between the rollover number, | ||
Line 130: | Line 163: | ||
====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 | 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==== | |||
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 | This protocol is used during the text-mode part of PC boot, when the BIOS is still in control | ||
because | 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 | 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 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?=== | |||
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 | * 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. | |||
That it's 125Hz for most keyboards is also true. | |||
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 | 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 | The crux here is that the USB-versus-PS/2 argument focuses only just a small part of this - steps 5 to 6. | ||
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 | * the debouncing necessary - assume it's within between 5ms..25ms | ||
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"
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: