I am looking for a way to track the duration of a key press in gamemaker. I was looking into alarm functions, but I figured there's a more elegant way. How can I track the duration of a keypress?
\$\begingroup\$
\$\endgroup\$
You could simply have a variable that you will increment each step if the key is currently down, and read its value once the key is released.
Create event:
keyTimer = 0;
Step event:
if (keyboard_check(ord('A'))) {
keyTimer += 1;
}
Key A Released event:
timePressed = keyTimer;
keyTimer = 0;
In this example, I am reading the time the user has pressed the A key and putting the value in the timePressed variable.