I'm building a C program to determine how many times a key is pressed in one minute (think "beats per minute") so I can use it later in a metronome I'm building.
I want to build something like this in C. How would I read the key presses as they happen?
Use
fgetc()
to read keypress of the ENTER key.Use
gettimeofday()
to measure time in microseconds, compute time elapsed from previous keypress, and divide 60s by it.You may want to average displayed values (e.g. keep a running average) to reduce variance.