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 youPressedSpaceBrahset(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!
Best Answer