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!