Why Is the D Key Not Triggering Keyboard Events in My SvelteKit Game?

0
0
Asked By MellowCedar42 On

I'm building a 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 seems completely ignored in this particular tab, as if the physical key is not reaching the page.

I only changed the main Svelte page and its Sass styles. I also tried replacing the existing game logic with a simple keydown listener, switching from localhost to 127.0.0.1, building the app, and hiding the scrollbar in case it was interfering. None of that fixed the problem.

The project is written in TypeScript, although I haven't added all the type definitions yet. Could something in the event handling or browser environment be intercepting the D key?

3 Answers

Answered By AmberKite63 On

Try narrowing it down systematically: run the app on another machine, test a different browser, disable extensions, and compare the current version with the last commit that worked. A binary search through the commit history can quickly identify which change introduced the problem.

Language-input tools or keyboard utilities can also interfere with browser key events, so temporarily disabling those is worth checking if the key works everywhere else.

Answered By QuietMaple18 On

The commit history may point to the real cause. One of the later changes appears to attach event handlers differently and no longer removes them with `removeEventListener`. That can leave old handlers attached and create unexpected behavior after remounts or reloads.

The D key may just be a red herring. Make sure listeners are registered only once and are cleaned up when the Svelte component is destroyed. Store the handler function reference and remove that exact reference during cleanup.

Answered By PixelHarbor7 On

The missing TypeScript annotations shouldn’t make one physical key stop working. First check whether the event reaches the page at all by running something like `window.addEventListener("keydown", e => console.log(e.key, e.code))` in DevTools and pressing D.

If nothing is logged, temporarily disable Brave extensions, try a private window, and test in another browser such as Firefox or Chrome. Also check whether D works normally in the same tab when typing in DevTools or another input. That will help separate an application problem from a browser or OS-level issue.

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.