Tracking rate of keyboard press

I’m looking for an effective way to track the rate at which subjects press a key.
I essentially have a balloon blowup task- but the balloon expands on the screen not based on the number of presses but on the rate of pressing

if anyone has any ideas how to do that, i’d be most appreciative.


I’m doing something similar at the moment (counting button presses in 5 seconds).

If you save all key presses then you can count the number of responses using len(key_resp.keys)

In your Each Frame code you could save the length every couple of seconds and calculate the current rate by dividing the difference between the current and previous rate by your time interval.