fingers in stroop task

Cognitive psychologists typically measure behavior. Using PsyToolkit, you can do that with at least the following methods:

  1. Measuring how long it takes to press a keyboard button

  2. Measuring how long it takes to press a mouse button, or where the mouse it

  3. Measuring eye-movements (on Linux using an eye-tracker)

Number 1, measuring a keyboard button is probably the most common method, and here is a basic explanation of how this is done.

Main command

The main PsyToolkit command for checking when and which key is pressed is readkey. It has 2 arguments:

  • Argument 1: Which key should be pressed?

  • Argument 2: What is the maximum allow time to respond?

The word "readkey" refers to the fact that the computer "reads" information from the keyboard. It has nothing todo with human reading behavior.

In the example below, the keys command tells the computer that there are only two possible keys a particant can choose from, in this can the keys b and n. You can list as many keys as you wish. The readkey command tells the computer that the correct key is "b", that is, the first key (i.e., 1) given in the keys command. It also tells the computer that if there is no response withint 2000 ms (2 seconds), the computer will consider this a TIMEOUT and go on.

  keys b n
  readkey 1 2000
  save STATUS RT

After readkey, the variable RT containst the response time in milliseconds. The variable STATUS contains one of the followng values:

Numerical values Value in words







If you save the STATUS, it will be saved as a numerical value, that is, 1, 2, or 3.

Special keys

You can use special keys, such as the space bar, or the arrow keys. You can check the names of these special keys to be used in the keys command in the online documentation here.

Example code

In this example, the focus is on readkey. Everything else is kept as simple as possible, so that it is a very short code example.

This example has no further explanation, but here is what you need to do:

1) If you see a red rectangle, press the key "b" within 2 seconds 2) If you see a green rectangle, press the key "n" within 2 seconds

There will be 10 trials, which takes less than a minute.

First run the example below to see what happens. The actual performance level is presented on screen while doing the task.

And here is the explanation.

table mytable (1)
  "red rectangle"   1 255 0    (2)
  "green rectangle" 2 0   255  (3)

task simpletask (4)
  table mytable (5)
  keys b n  (6)
  delay 100  (7)
  show rectangle 0 0 100 100  @3 @4 0  (8)
  readkey @2 2000  (9)
  clear 1  (10)
  save @1 STATUS RT   (11)

block firstblock  (12)
  tasklist (13)
    simpletask 10  (14)
  end  (15)
1 In this experiment, we use a table to 'define' two experimental conditions (there are 2 table rows in this table)
2 Each table row has 3 elements. The first is a "human readable" description only for humans, it is in quotes. The second is the correct key from the keys list (see task below). Because a red rectangle requires the first key in the "keys" list below, we have "1" here, etc. The 255 and 0 are the colors for the red and green channels. We have full red (255) and no green (0).
3 The second table row describes the second condition. Note that we have a 2, because we want that people respond with the 2nd key of the keys list (n).
4 We give the task name. Each trial starts here.
5 We tell the computer that we use the table called "mytable" (there can be more tables, so we need to tell the computer)
6 There are two keys a participant can choose from, the b and n (they correspond to key number 1 and key number 2).
7 we wait 100 ms
8 we show a rectangle at X,Y coordinate 0 0, which is the screen center. The 100 100 is the width and height. The remaining 3 numbers are the red, green, and blue values (each between 0 and 255). They @ sign means that the values are chosen from one of the table rows. Each trial chooses a table row randomly.
9 Now we tell the computer to wait (up to 2000 ms) for a key press. We tell that the correct key is decribed in the second column of the table (which contains 1 or 2 values)
10 Once the participant has pressed the key, the first stimulus (hence 1) is cleared from the screen
11 We tell the computer to save the human readable part of the chosen table row (so that the data file can later be easily interpreted) and we save the STATUS of the readkey command (1, 2, or 3) and the RT in milliseconds. Look at the data produced by the demonstration and you see what the "save" command does.
12 We need a block, which tells the computer how often to do the task
13 We need a list of tasks, we need to start with tasklist.
14 Everything between "tasklist" and "end" tells the computer which task to do and how often. Here we tell the computer to do simpletask 10 times. Each time it will be called, the computer will randomly choose one of the 2 defined possible conditions.
15 The "end" just tells the computer that this is the end of the "tasklist".