When you buy a new mechanical keyboard—or troubleshoot a sticky laptop key—the first thing you usually want to check is whether simultaneous keypresses actually register.
In this post, I'll walk through how we implemented real-time keyboard diagnostics in TypeBench using standard browser KeyboardEvent APIs and a static Next.js export.
event.key vs. event.code
A common pitfall when building an online keyboard tester is relying on event.key. Because event.key reflects the active OS keyboard layout and modifier state (for example, Shift + a produces A, and IMEs can emit Process), tracking physical key switches reliably requires event.code.
Using event.code maps directly to the physical key position (KeyA, ShiftLeft, NumpadEnter), which makes it possible to test multi-language layouts consistently.
Tracking Simultaneous Keypresses (NKRO & Ghosting)
To measure N-key rollover in our keyboard ghosting test and key rollover test, we maintain a Set of currently depressed event.code values:
- On
keydown: ignoreevent.repeat, addevent.codeto the active set, and record the peak simultaneous count. - On
keyup: removeevent.codefrom the set. - On
windowblur: clear the active set soAlt+Tabor OS shortcuts don't leave keys stuck in the UI.
You can also run into browser and OS-level intercepts (such as Cmd+W, Ctrl+T, or macOS Mission Control shortcuts) that never reach the page—so calling event.preventDefault() where permitted helps keep focus inside the test canvas without breaking normal browser navigation outside it.
Try It Out
All tools—including the 1-minute typing test and hardware diagnostic pages—run 100% client-side with zero signup across 9 languages. If you spot any key-code edge cases on non-ANSI layouts, let me know in the comments!
Top comments (0)