How I can make Last Button ID in Javascript?


#1

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


#2

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.


#3

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


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

#5

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


#6

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


#7

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


#8

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.