I am trying to understand how to correctly use KbQueue.
Assuming that I have a infinite loop (while 1) I want to break the loop if the space key is pressed.
Is the following correct?
KbWait; % press any key to start the movement
% create keyboard monitoring queue with target buttons
keyFlags = zeros(1,256); % an array of zeros
keyFlags(44)=1; % monitor only spaces
dvc = GetKeyboardIndices;
KbQueueCreate(dvc, keyFlags); % initialize the Queue
EXIT_SIGNAL = 0;
while ~EXIT_SIGNAL
KbQueueStart;% start keyboard monitoring
# some moving stimuli here
KbQueueStop;
[pressed, firstPress, firstRelease, lastPress, lastRelease]=KbQueueCheck;% check if space was pressed
if pressed
if any(strcmp(KbName(find(firstPress)), 'space'))%if space was pressed
EXIT_SIGNAL = 1;
KbQueueRelease;
sca;
end
end
end
Is it correct to put KbQueueStart
inside the loop? Or maybe outside?
Any better more “correct” way to do that?