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(~,~) ......
Best Answer