Per is exactly right, this sort of a question calls for the use of the KeyPressFcn.
The idea is to make a figure that waits for key presses. When the first key is pressed it calls a function that checks what time it is and updates a variable. Afterwards the function ignores any key except 'enter', which causes it to compare the current time to the time the first key was pressed.
If you save the following code as a single function then you should get the behaviour you are looking for:
function keyboard_timer
global typing_detected
typing_detected = 0;
h1 = figure;
set(h1,'KeyPressFcn',@detect_key_event)
function detect_key_event(hObject,~)
global typing_detected
key = get(hObject,'CurrentCharacter');
switch double(key),
case 13
elapsed = rem(now - typing_detected,1)*216000;
typing_detected = 0;
display(['Elapsed Time was ',num2str(elapsed)])
otherwise
if typing_detected==0,typing_detected = now;end
end