Objectives
Using Psychopy for the experimental procedure, MATLAB to analyse the EEG data, and JASP to conduct Bayesian analyses on the behavioural data. Grade: 9.5 Research Intern in Computational Neuroscience Vrije Universiteit Amsterdam (VU Amsterdam) jan. PsychoPy is an open-source package for creating experiments in behavioral science. It aims to provide a single package that is: precise enough for psychophysics; easy enough for teaching; flexible enough for everything else; able to run experiments in a local Python script or online in JavaScript.
- Be able to collect responses from the keyboard, knowing which key was pressed and when it was pressed.
We have already encountered the way in which we can collect participant responses via our use of psychopy.event.waitKeys()
and psychopy.event.getKeys()
.Here, we will take a closer look at these functions and how we can use them in vision science experiments.
Knowing which keys were pressed
We often want to know which key was pressed, not just that any of the keys were pressed.The “key” functions in psychopy return a list of strings, where each item in the list is a string representation of the key that was pressed.For example, if we run the following and press the “d” key, we can see that the item in the list is “d”: The mixologist leroy neiman.
Arduino serial in. Tip
Why is keys
a list, rather than just a string? This is to account for a situation in which multiple keys are pressed simultaneously.
Psychopy 2020
The string that represents the key that was pressed is straightforward for most of the keys.However, we often want to use the “arrow” keys, and it is not immediately obvious what the string representation will be.Let’s have a look by running the above again but pressing the “left arrow” key:
As you can see, the arrow keys correspond to “left”, “right”, “up”, and “down”.If you are unsure what the string representation of a particular key is, you can use a method like that shown above to find out.
Restricting the available keys
During an experiment, a participant usually only has a narrow range of keys that are meaningful.To prevent an accidental keypress prematurely ending a call to waitKeys
, we can provide a keyList
argument that restricts the keys that it “listens” to.For example, if we know that participants can only respond by pressing the left or right arrow key, it is often sensible to use:
This way, the only way that waitKeys
Cares act copay. will return is if the left or right arrow key is pressed—it will keep waiting if another key, such as the spacebar, is pressed.
Determining when a key was pressed
Psychopy App
It can also be useful know the time that a keypress was made (such as in studies of reaction time, though care needs to be taken if precise time estimates are required).We can easily obtain this information by providing a timeStamped
argument with a timing clock:
Psychopy Tutorial
You can see that what is being returned to us now is a list of lists (technically a list of tuples, which are similar to lists), where each item in the list is a pairing of the key that was pressed and the time it was pressed, relative to the clock timing that was provided to the function.