Was ZX spectrum better at handling than later PCs-keyboards without having diodes in its key matrix? I encountered this comment on ycombinator but I fail to understand it. Couldn't be Speccy method scaled to 101-key keyboards and the likes?

beagle3 on Mar 8, 2014 [–]

The ZX Spectrum in 1982 (and I'm quite sure its ancestors ZX-80 and ZX-81 from their eponymous years) had a keyboard just as cheap or cheaper, with a similar matrix arrangement), but had no ghosting at all:

Instead of having an "all hot" electrical configuration, it would cycle through the rows with a "one hot" configuration, and read the columns. If I recall correctly, it would be something like 20 cycles of a 4Mhz Z-80 to read one 5-column row (you'd need 8 of them to read the entire 40-key keyboard), and it was done every 50hz/60hz interrupt by the main CPU - modern keyboards have an ASIC on par or 100 times faster than a Z-80 just for the keyboard.


As far as I did my own experiments with the ZX Spectrum keyboard, I strongly disagree with that quoted text. The ZX Spectrum keyboard did ghosting, of course.

Let's look at the key matrix: ZX Spectrum keyboard

Imagine you press A, S, and Z keys together. It results in a "ghosted" Caps Shift.

When the CPU starts to check the CS-Z-X-C-V row, it drives the A8 line to "0". This level goes through the Z key to the 2-W-S-Z column, through the S key to the row A-S-D-F-G and so on, through the A key to the 1-Q-A-CS column and to the D0 input.

I did those tests on my Spectrum 48k (Issue 2) back in the '80s and got the result I described. It may depend on values of pull-ups and many other circumstances, maybe later models have this ghosting fixed, but I have tried it and it worked that way.

  • Funny enough, that almost 40 years after the original ZX Spectrum, the so called 'ZX Spectrum Next' did nothing to avoid ghosting, which is still present there. – lvd Sep 17 '20 at 8:50
  • 5
    Because games were aware of this (and some of them even took advantage of this ghosting for cheat key entering, (if my memory serves well) and because it's complicated to add diodes in a keyboard membrane (you can indeed, but that would have been made the membrane to be more expensive to produce) – mcleod_ideafix Sep 17 '20 at 9:13
  • Clones that use a mechanical keyboard with a proper circuit board have added anti-ghosting features as well. antoniovillena.es/store/product/uno-2mb-custom-case – mcleod_ideafix Sep 17 '20 at 9:15
  • 1
    "more expensive to produce" is not an argument for the already price-skyrocketed Next :) – lvd Sep 18 '20 at 8:01
  • 1
    Well... if you want to talk about the keyboard of the Next, we could stay here for hours, but to put it in a few words: they screwed it up. They didn't want to (or didn't know about) use the +2A/3 keyboard matrix scheme. Instead, they tried triple membrane. Didn't work. Had to switch back to double membrane with an semi-incompatible matrix, so the core had to scan the matrix in hardware and "virtualize" the Specrtum keyboard. Amstrad didn't need to do that, and worked like a charm. – mcleod_ideafix Sep 18 '20 at 23:10

The code responsible for scanning a keyboard can detect situations where ghosting may occur, and suppress the reporting of any keypress which might be a ghost press (e.g. situations where four or more keys seem to be pressed at once). Doing this slightly complicates keyboard logic, but generally not be a huge amount (if a keyboard scan differs from the previous scan, record the contents of the current scan for comparison with the next one, but don't otherwise act upon it). Alternatively, if a keyboard needs to detect combinations of two modifiers plus certain other keys, it could arrange the keys in question to either ensure that no combination of three keys would form the corners of a rectangle, or at minimum ensure that they would never form the corner of a rectangle whose fourth corner would also be a "plausible" key.

  • As I recall, the ZX Spectrum only supported two modifier keys, and then not both at the same time (as that was actually a keystroke in itself), so it only had to validate a trivial subset of scan results. – Neil Sep 17 '20 at 23:40
  • This is possible, but ghosting is not about just 4 keys, it is about 4 keys in a rectangle. If there are for example 8 keys seem to be pressed, cumbersome slow algorithms are needed to detect all rectangle patterns, not to say that there is absolutely no way to detect which three keys of the ghosting four are actually pressed. Same with modifiers, there would be need to scan the list of all allowed modifiers+keys to filter out some (not all!) ghosting. So I suppose even if the ghosting was taken in the accout during software developing, sane resolution would be 'just do nothing'. – lvd Sep 18 '20 at 7:58
  • @lvd: There are a variety of keyboard scanning algorithms that can be used, based upon what combinations of keys are expected. If e.g. all modifiers are on one row, and all expected key combinations involve at most one non-modifier key, rejecting any key scan that would show more than one non-modifier key would be fairly simple. – supercat Sep 18 '20 at 13:54

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.