17

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.

leopal
  • 173
Long
  • 181
  • 1
  • 5

4 Answers4

26

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).

hobbs
  • 1,492
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.

LPChip
  • 66,193
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.

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).