M
M
Maxim Siomin2020-06-22 20:23:57
Python
Maxim Siomin, 2020-06-22 20:23:57

How to make the system take into account only the new keystroke?

It is necessary that the system performs an action on pressing a key.

keys = pg.key.get_pressed()

if keys[pg.K_PAGEUP]:
            if yellowNumber == 2 or yellowNumber == 3:
                yellowNumber -= 1

The system does what it needs, but at the same time, since 60 fps, and each frame keysis updated, in order for the element to move only by 1, you need to press the key for ... 1.67 hundredths of a second, which is physically impossible. And I need to make it so that the system reacts only to a new click

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alan Gibizov, 2020-06-22
@phaggi

Pressed - changed the state of the variable "last button". Held longer - there was a second pressing. We check if the button matches the contents of the variable "last button" - ignore it.

E
Elvis, 2020-06-23
@Dr_Elvis

I don’t know exactly how pygame works, but I assume that when you click, you need to immediately block the button, and then do the calculations, and at the very end, unblock the button.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question