How to monitor key press in backround?

Hello! We want to use psychtoolbox to do an acoustic experiment, in which EEG signals of subjects are recorded throughout the experiment. During the experiment, the subjects will give some feedback (via keyboard) according to the stimulus content. However, during the experiment, the subject may touch the keyboard by mistake. We want to record every detail as much as possible (when the subject presses the key at any time, the program can send an “Event” to the EEG recorder through NetStation). Therefore, we want to know if there is any way to monitor the key situation in the background and send an “Event” to the EEG device while the main program is running.

The program in KbQueueDemo.m seems to be related to my needs, but how can I combine sending “Event” with pressing keys (without affecting the main program). Do I need to use multithreading?

Thank you very much!!!

You can’t. The KbQueueDemo approach lets you record key presses in the background, but it currently won’t let you send some Event to the EEG recorder each time a key is pressed.

However, for an acoustic experiment you could use a while loop in your script to do the keyboard checking and event sending, while the PsychPortAudio driver plays your sounds in the background though, as PsychPortAudio does run multi-threaded and independent of what your script does. Various of our sound demos show that parallelism.

-mario