Hello everyone!
I’m trying to program a Matlab routine on Windows, the idea is to press a mouse click following an audio signal. I need hi precision, so after reading the documentation I decided to use PsychHID functions.
In the first place, I’m trying to capture the event mouse click during 5 seconds and get time, then accumulate it in a vector ([times]) but it doesn’t work, sometimes it gets more events than I clicked and the time between clicks is always the same.
Did somebody try this before? I will be grateful for any help
Here is my code:
Hi dcniecho,
Thank you for your answer.!You are right, better to use GetMouseIndices().
My question is: if I do not use a loop how can I save the event time? reading the documentation the function will return only the last event.
I need to capture all of them and calculate the intervals between them.
As mario said, don’t use PsychHID directly. Also, read the queue once like i said:
devices=PsychHID('Devices',1 );
mouseIndex=GetMouseIndices();
KbQueueCreate(mouseIndex);
KbQueueStart(mouseIndex);
pause(5)
% now get what happened during those 5 s
events = [];
nremain = inf;
while ~~nremain
[e,nremain] = KbEventGet(mouseIndex);
events = [events e];
end
KbQueueStop(mouseIndex);
KbQueueRelease(mouseIndex);
% see how many clicks and inter click intervals
mouseDowns = [events.Pressed]==1;
pulses = sum(mouseDowns)
interv = diff([events(mouseDowns).Time])
They’re not meant to be. The KbQueue* wrapper matlab files take care of some input handling and such to make sure things operate correctly. That how they were designed by Mario, so listen to what he says there.