# Recording key press while stimuli are being shown

**URL:** <https://psychtoolbox.discourse.group/t/recording-key-press-while-stimuli-are-being-shown/354>\
**Category:** Uncategorized\
**Created:** [February 18, 2013, 5:23am UTC](https://psychtoolbox.discourse.group/t/recording-key-press-while-stimuli-are-being-shown/354 "2013-02-18T05:23:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![psyliupan](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@psyliupan](https://psychtoolbox.discourse.group/u/psyliupan)\
**Post date:** [February 18, 2013, 5:23am UTC](https://psychtoolbox.discourse.group/t/recording-key-press-while-stimuli-are-being-shown/354/1 "2013-02-18T05:23:41Z")

</div>

Hi  
  
I am using Matlab to write an experiment code.  
  
In this experiment, a number stream will be presented at the screen center (i.e. several numbers will be shown one by one).  
  
This number stream will be shown for 4 s (each number for 0.2 s, with a 0.2-s break between two numbers), and then there is a big break (2 s).  
  
I want to record the key press (either M or N, other key presses will be invalid and be ignored) while the numbers are being shown. This key press can happen anytime during the 4 s. And the stream will be presented for exactly 4 s, no matter there is a key press or not.  
  
Actually, it would be better if the computer can play a warning sound when participants make a wrong key press.  
  
However, I don't know how to do this with Matlab PsychToolBox.  
  
Can anyone please help me with this?  
  
Thank you so much!
