I am using [keyIsDown,secs,keyCode]=KbCheck; inside a loop to check if specific keyboard buttons are pressed. This controls the movement of a ball. E.g. by pressing a button one time, the ball moves one location to the right.
Sometimes, it is hard to place the ball in an exact predefined location because a “longer than should be” button press results in a more fast/far movement (e.g. some position after the target position). How can I control this “sensitivity”? Ideally, I need to wait some ms for the button to be unpressed and then allow another button press but KbCheck cannot do that.
Do you want the ball to keep moving indefinitely if the subject holds the button down? Or do you just want the ball to move a certain distance when the button is pressed, but then no farther even if the user holds the button down?
I tried this but now it is extremely slow to move the ball to the desired position. This is because the main loop iterates over all frames and this command makes this too slow.
RestrictKeysForKbCheck([d f g]);
[keyIsDown,secs,keyCode]=KbCheck;
if keyCode(d)==1
count2=count2-1; % go anti-clockwise
elseif keyCode(g)==1
count2=count2+1; % go left
elseif keyCode(f)==1
keydown2=1; % got confirmation
end
KbReleaseWait;
Hi thanks for the suggestion. Unfortunately, it leads to the same behavior as explained in my comment above. I found a workaround using WaitSecs(1/fps) as:
[keyIsDown,secs,keyCode]=KbCheck;
if keyCode(d)==1
count2=count2-1;
WaitSecs(ifi);
elseif keyCode(g)==1
count2=count2+1;
WaitSecs(ifi);
elseif keyCode(f)==1
keydown2=1; % got confirmation
end