You mentioned that you would prefer it in C, but since you marked it with Python ... :)
In addition, since you are saying that you are looking for creating a data set, I assume that you will have to invite users to enter arbitrary text, so you will need some kind of interface (graphical or another).
Here is a quick example of using pygame. You can trivially change it to ask users to type specific words, but as it is, it simply allows the user to enter arbitrary text, record the time for all keystrokes, and print each hold and digraph in the order in which the user typed it, when it exits (that is, when the user presses Esc).
As Kibibu noted, showing the user what he is typing in real time, a delay is introduced that can mask real keystrokes, so this code only displays what the user typed when he types "Enter."
Update: Now it calculates the digraph and hold time (excluding Enter in both cases).
Update2: Per Adi query changed from displaying the average to displaying each individual time in order.
import sys from collections import defaultdict from time import time import pygame from pygame.key import name as keyname from pygame.locals import *
source share