
Building a Typing Speed Trainer in React (and with the help of Amazon Q)
In this post, I’ll share how I developed a React-based typing speed trainer game with the assistance of Amazon Q, an AI-powered code generation tool. We’ll dive into the project’s concept, the coding process, and how Amazon Q helped streamline the development, turning a basic idea into an interactive, timed typing challenge.

- A random enabled key is highlighted on a visual keyboard.
- The player has 60 seconds to correctly press as many highlighted keys as possible.
- Each correct press yields points and builds a streak, while an incorrect press resets the streak and is noted as a miss.
- At the end of the round, the user sees their final score, streak, and accuracy percentage.
keyboardCharacters.tsx
file that defined the keyboard rows, keys, and their properties (like disabled
states and widths for layout). By isolating this data, I kept the main game logic lean and flexible. If I want to add or remove keys later, I only need to modify this one file.getRandomEnabledKey()
to return a random target key. This automation freed me to think about the user experience instead of manual indexing and filtering.
App.tsx
, I set up React state hooks to handle key game aspects:- State Management:
score
,streak
,wrongCount
to keep tabs on performance.randomKey
to store the currently active target key.timeline
to visually represent a recent history of correct (y) and incorrect (n) attempts.
- Timer:
A 60-second countdown challenges the player to type correctly and swiftly. I usedrequestAnimationFrame
for smoother updates. With Amazon Q suggesting patterns for interval-like updates using React’s hooks, I seamlessly integrated the timer logic. - Key Events:
keydown
events determine if the user’s typed character matches therandomKey
. Amazon Q’s quick code suggestions helped me structure the event listener cleanly. On correct input, thescore
andstreak
rise, the timeline records a “y,” and a new random key is selected. On incorrect input, thestreak
resets,wrongCount
increments, and the timeline logs an “n.” - Visual Feedback & UI Layout:
The UI displays:- The timer at the top.
- A visually rendered keyboard (each key sized and positioned according to
keyboardCharacters.tsx
). But I forgot how to display the keyboard characters in upper case. Well Amazon Q came in handy again! This time it was the chat feature provided by Amazon Q.Amazon Q Chat Feature - Real-time metrics (score, streak, accuracy) on the side.
- A green or red glow effect to provide immediate feedback on each attempt.
- Streamlined Development: Amazon Q reduced the initial coding overhead, making the project more enjoyable.
- Improved Code Organization: By separating logic into distinct files and states, maintaining and updating the code is straightforward.
- Flexibility for Growth: I can easily tweak the enabled keys, adjust the timing, or incorporate leaderboards and user-defined key sets in the future.