Why Is the D Key Ignored Only in My SvelteKit Game?

0
0
Asked By MellowPine42 On

I'm building a small Three.js game with SvelteKit, Vite, and TypeScript on Windows 10 using Brave. The A, S, and W keys work normally, but the D key appears to be ignored in the game's browser tab, almost as if the physical key stops working there. I mainly modified src/routes/+page.svelte and its styling file. I also tried registering a minimal keydown listener, switching between localhost and 127.0.0.1, building the project, and hiding the scrollbar, but none of that fixed the issue. Could missing TypeScript types or the way my keyboard event handlers are attached be causing this?

3 Answers

Answered By QuasarBicycle7 On

First determine whether the browser is receiving the key at all. In DevTools, run window.addEventListener('keydown', e => console.log(e.key, e.code)) and press D. If no event appears, try disabling Brave extensions, using a private window, or testing in Chrome or Firefox. Also check whether D works in another input on the same page. Missing TypeScript annotations would not normally make one physical key disappear completely.

Answered By CedarOrbit5 On

Narrow it down systematically: test a known-working commit, then use a binary search through the commits to find the change that introduced the problem. Also test on another machine or browser. That will tell you whether the cause is in the application, the browser, an extension, or keyboard software such as an input method.

Answered By HarborMango18 On

The commit history suggests the D key may be a red herring. A later bug-fixing change altered how the event handlers are attached and stopped removing listeners. If the component keeps adding handlers during updates or remounts, you can get stale or duplicated listeners and confusing behavior. Make sure every addEventListener has a matching removeEventListener, ideally by defining the handler once and cleaning it up when the component is destroyed.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.