Download www/js/controls.js from 1024m/HF-Racing: direct link, hf CLI and curl.
- Browser
- Download file 943 Bytes
-
https://huggingface.co/spaces/1024m/HF-Racing/resolve/main/www/js/controls.js
- Command line
-
hf download hf://spaces/1024m/HF-Racing/www/js/controls.js
-
curl -L -o controls.js https://huggingface.co/spaces/1024m/HF-Racing/resolve/main/www/js/controls.js
943 Bytes
| /** Keyboard driving input (WASD / arrows). */ | |
| export class DriveControls { | |
| constructor(target = window) { | |
| this.keys = new Set(); | |
| this._down = (e) => this.keys.add(e.code); | |
| this._up = (e) => this.keys.delete(e.code); | |
| target.addEventListener('keydown', this._down); | |
| target.addEventListener('keyup', this._up); | |
| } | |
| dispose(target = window) { | |
| target.removeEventListener('keydown', this._down); | |
| target.removeEventListener('keyup', this._up); | |
| } | |
| sample() { | |
| const forward = this.keys.has('KeyW') || this.keys.has('ArrowUp'); | |
| const back = this.keys.has('KeyS') || this.keys.has('ArrowDown'); | |
| const left = this.keys.has('KeyA') || this.keys.has('ArrowLeft'); | |
| const right = this.keys.has('KeyD') || this.keys.has('ArrowRight'); | |
| return { | |
| throttle: (forward ? 1 : 0) - (back ? 1 : 0), | |
| steer: (left ? 1 : 0) - (right ? 1 : 0), | |
| brake: this.keys.has('Space') ? 1 : 0, | |
| }; | |
| } | |
| } | |