15

Context

A friend and I are playing a game where the optimization to playing a given character in the game is to hold down two buttons at once, i.e. they keys Q and E. This would mean that within the game the two skills bound to these keys would go off alternatively.

I.e. when holding Q and E: Q E Q E Q E Q E Q E

Problem

The issue arises in that I am unable to replicate what my friend has done when I hold down the keys Q and E. What I get instead is:

ie. when holding Q and E: Q E E E E E E E E E or E Q Q Q Q Q Q Q Q (depending one which key is detected first)

After discussing with my friend, he says its n-key rollover in addition to anti-ghosting that allows this to work.

However, once both of us began to look deeper into this, it just made less and less sense since both of our keyboards has the aforementioned features. Both of our keyboards are listed below if it provides additional context.

What I'm trying to figure out now is what allows his keyboard to operate the way it does, while mine cannot do the same.

  • 2
    A few questions, to clarify: You are just playing an existing game, correct? Or are you developing the game? Are you playing on PC? Mac? A console (with keyboard attached)? If PC, are you on the same OS (Windows 10 vs say Windows 7 or a flavor of Linux)? – Doktor J Oct 28 at 14:16
  • 3
    Simple test - swap keyboards. – Vilx- Oct 28 at 22:57
25

Anti-ghosting only comes into play when at least three keys are pressed — it's irrelevant for only two, so it doesn't matter here.

And for USB keyboards, key repeat behavior is dependent on software, not the keyboard. The keyboard simply tells the computer all of the keys that are held down at the moment (up to the "rollover" limit supported by the keyboard), and lets the computer know whenever that state changes. It's the OS that's responsible for comparing the list of held keys to the previous state and generating the appropriate "key pressed" and "key released" events, and it's the OS that's responsible for noticing when a key has been held down for a certain amount of time and generating extra events, if appropriate.

Every system I've ever seen behaves the way you describe your system behaving — typematic only generates repeats for the last key that was pressed, and only as long as it's held down (if you release that key, but still hold down other keys that were pressed earlier, there are no repeats at all). But since the behavior is defined by software, it should be possible to override it in software, as long as the keyboard is at least 2KRO (which basically all keyboards are; 1KRO would make proficient touch typing basically impossible).

| improve this answer | |
  • 4
    +1 for the answer, but disagree with "1KRO would make proficient touch typing basically impossible", since touch typing was and is done on mechanical typewriters, and these are effectively only 1KRO since otherwise the type bars/strikers (holding the letters shapes) collide! – user7761803 Oct 28 at 10:08
  • 1
    This answer only holds true for newer keyboards, usually labeled gaming keyboards. LGR, 8-bit guy, Linus tech tips, and various others, did good videos on youtube about old keyboards witn their matrixes and they really have a hardware limit. – LPChip Oct 28 at 11:32
  • 1
    @user7761803, I haven't used typewriters much, but I suppose you could have one striker advancing (one key going down) already while the previous one was still retreating (first key going up). What kind of rollover that counts as, well, I don't know :) – ilkkachu Oct 28 at 13:21
  • 2
    @ilkkachu: The required separation between keystrokes was greatly dependent upon key placement; consecutive type bars were much more prone to jam than those even one further apart. The first QWERTY typewriter had a set of type bars which were in zig-zag order on the top two rows, and another set that were in zig-zag order on the bottom two rows. The only problematic letter pair that appeared at all frequently in English text was "sc" [the bottom row of the first layout had ZCXV instead of ZXCV], which was fixed in later keyboards, where the only common words that have problematic pairs... – supercat Oct 28 at 21:45
  • 1
    @user7761803 It was a joke. Think about "touch" as in carefully calibrating the pressure applied by your fingers, as would have been necessary with said typewriters. – Asteroids With Wings Oct 30 at 12:31
11

In order to answer this question, one must understand how keyboards work.

If you look back to the earlier keyboards, you will realize that the plug has only a few pins on it, not the same number of pins as there are keys on the keyboard.

That said, if you press a key on the keyboard it is still instantly transfered to the computer without any delay. So how is this possible?

A keyboard works with a matrix of horizontal and vertical signals. All keys are layed out on a grid as shown on your keyboard. When you press a key down, it does not just say, key "x" is pressed down, but it will instead say, key on column 3 and row 5 has been pressed down. This means that in the end, the amount of data lines is not the number of keys, but only the number of rows and columns (optimized).

The problem now comes down when you press multiple keys at once, the matrix can now come in a state where it can't know for sure what key is pressed, which is why some keyboards can only press 2 keys at once and a 3rd key is ignored.

To combat this, the matrix has been redesigned to reduce this from happening, which is why some keyboards claim you can press 4 or 5 keys down, but if you find the magic combination, you get down to 2 again, but it happens far less frequently due to lots of trial and error.

Because this in the end still became a problem, other methods were used to actually support multiple keypresses, known as anti-ghosting. The problem here is that it can be achieved in many ways, which is why some keyboards give Q E Q E Q E, others do QEEEE or EQQQQQ.

So long story short, in an attemmpt to allow multiple keys to be pressed at once, depending on how much development budget and what method was used, the behavior of pressing multiple keys at once is different for different models.

Newer gaming oriented keyboards will send all keystrokes really fast to the computer, to the driver over USB which can tell the software what keys are pressed which shows QEQEQEQE, whereas older keys still use a matrix and use hardware keys, which only show QEEEEEEE or EQQQQQQ.

| improve this answer | |
  • 3
    Essentially, all keyboards are not created equal? And as a result of this inequality the behavior of each keyboard is different? That's quite fascinating when I think about, for companies that advertise their keyboard as the "best gaming" ones around, its surprising to learn that differences like this are possible. Please correct me if I misunderstood, but basically depending on the company, their drivers are different and thus result in different behaviors. – Long Oct 27 at 12:09
  • 2
    Not just the drivers, but the chips etc all can be different. – LPChip Oct 27 at 12:20
  • 13
    Note that most keyboards send only “key down” and “key up” events. The repeating is done by the OS. If you’re typing into a document to see what is happening, that is the wrong approach. Use a keyboard event viewer. – Reid Oct 27 at 22:12
  • 1
    Um, no, there are keyboards that actually do have true n-key rollover for n higher than 2 at least within the contents of a standard 61-key reduced layout (which is what usually matters for gaming). They’re just rather expensive because they need to be designed very differently from traditional keyboards, since each possible combination of up to n keys has to present a unique state to the internal MCU. I’m actually typing on one right now that has true 3-key rollover within the standard 61-key set. – Austin Hemmelgarn Oct 28 at 2:00
  • 1
    @AustinHemmelgarn yes, which is the anti ghosting. They have a chip inside that captures the keys and send them to the driver so the OS can handle it. See the last paragraph of my answer. – LPChip Oct 28 at 11:28
4

With a USB keyboard this kind of “autorepeat two keys at once” behavior happens in Windows if the keyboard sends the key press events for both keys in the same HID input report. I even tested this with a custom modification to the QMK keyboard firmware, where I can control exactly what HID input reports are sent over USB. Other operating systems may not have this behavior (e.g., Linux always chooses only one key for autorepeat).

As for why different keyboards have different behavior with respect to this feature, there may be several explanations:

  1. Timing the keypresses so that they would be reported in the same HID input report may be harder with a higher scan rate (so on an older keyboard with the 250 Hz rate triggering the double autorepeat may be easier than on a newer keyboard with the 1000 Hz rate).

  2. Although most “gaming” keyboards these days advertise “1000 Hz rate” (therefore keypresses which were made more than 1 ms apart should be reported in separate input reports), this kind of advertising is not always 100% honest — in particular, some debouncing algorithms may cause the reported keypresses to be synchronised even when the physical keypresses were detected more than 1 ms apart.

  3. Some keyboards may be performing special processing in the firmware (e.g., related to the macro support) which results in generation of separate HID input reports for every key state change — if the keyboard firmware is written this way, getting the “double autorepeat” from it would be impossible even with the most precise keypress timing.

| improve this answer | |
  • Being also a bit familliar with QMK and HID reports, I was also wondering how the keyboard itself would be able to do that. It would have to explicitly alternate between the two keys, which is certaintly not desirable, even for games. Having that handled by Windows itself seems to make more sense, although I wonder what is the benefit – and it does not look like something that would be done unintentionally. – Didier L Oct 28 at 13:47
1

A possible workaround is some keyboards support macros so you may be able to program a macro to do QE and then have it repeat while the macro key is held down. I used to do this in Diablo 2 or 3 on my old Razer Blackwidow. The Razor control app had a macro editor that would let me choose to send the sequence only once or repeat it until I stopped holding the key down. If you don't have dedicated macro keys you can just set the macro to a key that is not used in the game (maybe a function key or backtick or something like that).

| improve this answer | |
  • Or use some software like AutoHotkey – Caius Jard Oct 29 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.