Psychtoolbox doesn't follow timings

Hi,
I’m working on i7 HP, with Matlab 2021b and Pshyctoolbox 3.0.18 -m beta.

I’m trying to present a stimuli while recording keyboard activity.
I’m running the following code - which works fine on other computers:

imageTexture = Screen('MakeTexture', window, Image);
Screen('DrawTexture', window, imageTexture);
Screen('Flip', window);   
t0=clock;
j=0;
while etime(clock,t0)<0.25
    j=j+1;
    [Key(i,j),secs(i,j),KeyCode,deltaSecs]=KbCheck;
end

But the stimuli end up being presented for much less then 0.25 seconds, although when I check the timings it says that it was presented for 0.25 sec.

Thank you,

Solutions ordered in terms of both how much work they are and how
recommended they are:

  1. Use GetSecs not the matlab time functions, the latter may have
    pretty low resolution depending on clock hardware
  2. move to using KbQueues (see KbQueueDemo), along with using
    Screen(‘Flip’)'s when parameter for presentation timing, as
    recommended in the PTBTutorial-ECVP2013.pdf in the PsychDocumentation
    folder

Amazing! the first solution worked! Thank you

To emphasize Diedericks comment:

If you don’t use the timestamps and target times of the Screen('Flip') command, e.g., t0 = Screen('Flip', window) then your t0 may have no relationship to true stimulus presentation time at all, there could be arbitrary errors. We have many demos and help in the cited PDF file on how to do timing right, instead of fooling oneself or suffering from way less precision than possible.

-mario