user3380826
user3380826

Reputation: 127

Python limit key input per second

I have a raspberry pi that is setup to run different videos depending on the key press on a keyboard. If someone accidentally hits two keys at once, it causes the unit to temporarily freeze up. What is the best way and code to limit one key press of keys x,y,z for two seconds?

Upvotes: 1

Views: 355

Answers (1)

holdenweb
holdenweb

Reputation: 37033

Just record the time when each keypress comes in, and store the last couple. If the time of the next keypress is shorter than your required threshold, just ignore it.

Upvotes: 2

Related Questions