CodeAgeBy Sitezack
Canvas pour CréateursDessine et anime ton jeu0 XP
Progression du chapitre0/6

Leçon 5 sur 7

Piloter au clavier

document.addEventListener('keydown', …) écoute le clavier : l'événement reçu contient event.key ('ArrowRight', 'ArrowLeft'…).

Un if sur event.key et ta fonction moveCar fait le reste — ta voiture répond aux flèches !

document.addEventListener('keydown', function (event) {
  if (event.key === 'ArrowRight') {
    moveCar(10);
  }
});

🎯 Ton objectif

Écoute le clavier : la flèche droite (ArrowRight) appelle moveCar(10), la flèche gauche (ArrowLeft) appelle moveCar(-10).

Leçon PRO

Ce chapitre avancé fait partie de CodeAge PRO. Débloque-le pour continuer ton aventure.

Découvrir PRO