kbcheck doesn't detect key release

Hi everyone,

I need my program to detect the time period for which a key remains
pressed, but kbcheck doesn't seem to detect the release of the key.
I have version 2.54 (for Windows) and this problem was supposed to
have been corrected in an earlier version, but it seems to still
persist.

Here's a sample of the code I tried:

function time = keyDur()
validPress = 0;
while ~validPress
[touch, secs, keyCode] = KbCheck;
if strcmp(KbName(keyCode),'down')
startTime = KbWait;
kdown = 1;
while(kdown)
WaitSecs(0.01);
[touch, secs, keyCode] = KbCheck;
if strcmp(KbName(keyCode),'down')
kdown = 1;
else
b = KbWait;
kdown = 0;
end
end
endTime = KbWait;
validPress = 1;
end
end
clc;
time = endTime - startTime;

Is there something I'm missing about KbCheck? Thanks a lot,

Vani