How do i make a button that clicks w like a key

how do you make a button for mobile that clicks w in a web game something like this.

that clicks w like a key

Well, if you’re trying to make mobile controls, it’d be better to call all of your functions that are called when W is pressed, when the button is clicked. Is it like that?

Do you want to make virtual keys that works on mobile, don’t you?

yes can you make one to show me how

you can try making a <button> tag that shows a W and add an onclick event that fires any js functions you have that run when a player presses the W key

how about this?

As I said, you can make a <button></button> tag that has an onclick attribute that will call your event functions. Example code:

<button onclick="moveUp()">W</button>

And then in your JavaScript, include the function declaration and other logic; for example:

document.addEventListener('keydown', (e) => {
    if (e.key=="w") {

function moveUp() {
    // Put your logic for controlling the character here
1 Like