CoolFace
Apppublic

RustX/Autonomous_Driving_Simulation

sourceHugging Faceupdated 3y agoView on Hugging Face
3likes
controls.js54 linesDownload Raw Back to root
1class Controls{2    constructor(type){3        this.forward=false;4        this.left=false;5        this.right=false;6        this.reverse=false;7 8        switch(type){9            case "KEYS":10                this.#addKeyboardListeners();11                break;12            case "DUMMY":13                this.forward=true;14                break;15        }16        17        18    }19 20    #addKeyboardListeners(){21        document.onkeydown=(event)=>{22            switch(event.key){23                case "ArrowLeft":24                    this.left=true;25                    break;26                case "ArrowRight":27                    this.right=true;28                    break;29                case "ArrowUp":30                    this.forward=true;31                    break;32                case "ArrowDown":33                    this.reverse=true;34                    break;35            }36        }37        document.onkeyup=(event)=>{38            switch(event.key){39                case "ArrowLeft":40                    this.left=false;41                    break;42                case "ArrowRight":43                    this.right=false;44                    break;45                case "ArrowUp":46                    this.forward=false;47                    break;48                case "ArrowDown":49                    this.reverse=false;50                    break;51            }52        }53    }54}