How I can make Last Button ID in Javascript?

How can I save the id of the last button pressed (in javascript keycode) and store it in a variable??

Define “it” and “the id value”, and what it has to do with a “last button id”. If you use your own invented terminology and don’t describe your issue clearly, no one will ever be able to help you.

How can I save the id of the last button pressed (in javascript keycode) and store it in a variable?

document.body.addEventListener("keyup", function(e) {
runtimeScene.getVariables().get("keycode").setNumber(e.keyCode);
});

Thanks but I can´t understand
How work this code?

Paste it into a javascript event and then the gdevelop scene varibale “keycode” will contain the js keycode from the last key pressed.

1 Like

Thank you it worked
But how can I make it run only once while true in Javascript?!
Edit: I try that but don´t work

If you use the pressed and not released action, you can replace “keyup” with “keypress” in JS, but ya in both cases the very first key press is not tracked if the JS does not run without a condition. I don’t know why and if it can be fixed.