Download controls.js from RustX/Autonomous_Driving_Simulation: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/RustX/Autonomous_Driving_Simulation/resolve/main/controls.js
- Command line
-
hf download hf://spaces/RustX/Autonomous_Driving_Simulation/controls.js
-
curl -L -o controls.js https://huggingface.co/spaces/RustX/Autonomous_Driving_Simulation/resolve/main/controls.js
1.39 kB
| class Controls{ | |
| constructor(type){ | |
| this.forward=false; | |
| this.left=false; | |
| this.right=false; | |
| this.reverse=false; | |
| switch(type){ | |
| case "KEYS": | |
| this.#addKeyboardListeners(); | |
| break; | |
| case "DUMMY": | |
| this.forward=true; | |
| break; | |
| } | |
| } | |
| #addKeyboardListeners(){ | |
| document.onkeydown=(event)=>{ | |
| switch(event.key){ | |
| case "ArrowLeft": | |
| this.left=true; | |
| break; | |
| case "ArrowRight": | |
| this.right=true; | |
| break; | |
| case "ArrowUp": | |
| this.forward=true; | |
| break; | |
| case "ArrowDown": | |
| this.reverse=true; | |
| break; | |
| } | |
| } | |
| document.onkeyup=(event)=>{ | |
| switch(event.key){ | |
| case "ArrowLeft": | |
| this.left=false; | |
| break; | |
| case "ArrowRight": | |
| this.right=false; | |
| break; | |
| case "ArrowUp": | |
| this.forward=false; | |
| break; | |
| case "ArrowDown": | |
| this.reverse=false; | |
| break; | |
| } | |
| } | |
| } | |
| } |