A beautiful, interactive 3D mechanical keyboard demo built with Vite and Three.js. Press your physical keys to see the 3D keycaps animate, hear satisfying switch samples, and experiment with themes, layouts, and lighting.
✨ Highlights
- Interactive 3D keyboard with realistic key animations
- Selectable switch sound sets (Red, Blue, Brown, Black)
- macOS / Windows labeling and multiple visual themes
- Lightweight: baked lighting, cached textures, and optimized meshes
- Clone the repo
git clone <repo-url>
cd keyboard
npm install- Start the dev server
npm run devVite serves the app (default port 3000) and should open your browser automatically.
To build for production:
npm run build
npm run preview- Press any physical key to animate the corresponding 3D keycap and play a switch sound
- Toggle layouts between
macOSandWindows(legend rendering updates automatically) - Change themes and dark mode from the settings panel
- Adjust room lighting intensity for different presentation moods
- Scroll to zoom the camera (rotation and panning intentionally disabled)
index.html— App shell and UI controlssrc/main.js— Bootstraps the Three.js scene, UI wiring, and animation loopsrc/Keyboard.js— Builds and rebuilds the keyboard mesh from layout datasrc/Key.js— Keycap geometry, legend rendering, and press animationssrc/KeyboardLayout.js— 65% layout, key sizes, and theme color lookupsrc/InputHandler.js— Maps browser keyboard events to animations and audiosrc/SoundManager.js— Loads switch samples frompublic/sounds/and plays themsrc/SettingsManager.js— Centralized settings (layout, theme, dark mode)
Public assets
public/sounds/— Switch audio files named{switch-type}-{index}.mp3
- Use the setters in
src/SettingsManager.jsto change layout/theme so events keep the UI in sync - When rebuilding the keyboard, dispose of old meshes/materials/geometries and call
clearKeyCaches()to avoid memory leaks - Keep asset paths root-relative (e.g.
/sounds/red-1.mp3)
npm run dev— Start Vite dev servernpm run build— Create production bundlenpm run preview— Preview production build locally
Contributions welcome — open issues or PRs. For UI changes, preserve the baked-lighting approach and avoid enabling real-time shadows.