Psychtoolbox按键代码(MATLAB)

根据按下的上下箭头反馈对应的文字

%% keyboard arrow
%初始化ptb
PsychDefaultSetup(2);
[wptr, windowRect] = PsychImaging('OpenWindow', 0,0,[0,0,1920,1200]);
%设置按键
upKey = KbName('UpArrow');
downKey = KbName('DownArrow');
%操作提示
feedbacktext='up:↑             down:↓\n\nwhen screen is black\nselect in 2 seconds';
justSaySomething(wptr, feedbacktext);
WaitSecs(2);
Screen('Flip',wptr);
%两秒钟时间做出按键选择
t=GetSecs;
while GetSecs<t+2
[keyIsDown,secs, keyCode] = KbCheck;%获取按键
if keyCode(upKey)
   justSaySomething(wptr, 'up');
   WaitSecs(1);
   Screen('Flip',wptr);
   elseif keyCode(downKey)
          justSaySomething(wptr, 'down');
          WaitSecs(1);
          Screen('Flip',wptr);
end
end
%结束语
justSaySomething(wptr, '@Dong, XJTU, iHarbour, 2020');
WaitSecs(1);%1秒钟的展示
%关闭窗口
Screen('CloseAll');

其中justSaySomething文字显示函数在另一篇psychtoolbox创建屏幕窗口并显示文字内容(MATLAB)

你可能感兴趣的:(#,Psychtoolbox)