3
\$\begingroup\$

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?

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.