how to count key presses in limited time?
이전 댓글 표시
its aquestion I've asked before, and got some answers, but I'v just found out that it doesnt count key presses- it counts also if I just hold the key pressed wthout releasing it- and thats no good...
this is what I have now- and I want to fix somehow-
%State variables
count = 0;
allowCounting = false;
%Timer
t = timer('StartDelay',10,'TasksToExecute',1,'StartFcn',@timerStarted,...
'TimerFcn',@timerFinished);
%Callback functions
%When the user presses a key
function youPressedSomething(~,eventdata)
%See if it is the space bar
set(a8,'Visible','off');
set(a9,'Visible','on');
set(th,'Visible','on','String',[ num2str(count) ]);
if strcmp(eventdata.Character,' ') && flag
if allowCounting
count = count+1;
set(th,'Visible','on','String',[ num2str(count) ]);
else
startTimer;
end
end
end
%Kick off the timer!
function startTimer
start(t);
end
%Callback for when timer starts
function timerStarted(~,~)
count = 1;
allowCounting = true;
end
%Callback for when timer finishes
function timerFinished(~,~)
......
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 DTMF에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!