How to capture time interval between two keypress.
이전 댓글 표시
I want to capture time between two keypress .Time when one key is released and next key is pressed.I made code using cputime.Its like
function Keyrelease_Test
h = figure;
set(h,'KeyReleaseFcn',@KeyUpCb,'KeyPressFcn',@KeyDownCb)
StartTime=0;
function KeyUpCb(~,~)
StartTime=cputime;
end
function KeyDownCb(~,~)
Time=cputime-StartTime;
disp(Time)
end
end
but when i press 3 key it gives output like: >> Keyrelease_Test 54.8968
0.1872
0
0.0156
but for 3 keypress it must give 2 time.please help me
i have also made code using now
function Keyrelease_Set
h = figure;
set(h,'KeyReleaseFcn',@KeyUpCb,'KeyPressFcn',@KeyDownCb)
t1=0;
t2=0;
function KeyUpCb(~,~)
t1=rem(now,1);
end
function KeyDownCb(~,~)
t2=rem(now,2);
Time=t2-t1;
disp(Time)
end
end
for 2 keypress it gives output like
Keyrelease_Set
0.8938
1.6852e-05
please help me with this code or i have to use any other function or logic??
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!