How to count how many times a button was pressed?
Afficher commentaires plus anciens
I want to write a code where I can check how many times a button was pressed (keyboard, mouse or even a pointer).
The code I have now is not working the way I want. As I click on a button for more than 1 second, it gives me a counting of 10 or more times. I want my code to count the number of clicks someone does on a button despite they spent 1second or 5seconds with the finger pressed against the button. Here is my function:
function youPressedSpaceBrah
set(figure,'KeyPressFcn',@youPressedSomething,'Name','Multitasking Game - Alerta Visual Nivel 1','NumberTitle','off', 'MenuBar', 'none','ToolBar', 'none');
clf;
%State variables
count = 0;
allowCounting = true;
%Callback functions
%When the user presses a key
function youPressedSomething(~,eventdata)
if strcmp(eventdata.Character,' ')
if allowCounting
count = count+1
end
end
end
end
Here is the code to call my function to the main code:
function youPressedSomething(~,eventdata)
erros=erros+1;
end
Thanks for your support!
Réponse acceptée
Plus de réponses (1)
Joana Alves
le 22 Nov 2017
0 votes
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!