Skip to content

keyboard

Experiments

Defines which physical keyboard keys are valid responses for a trial. When keyboard is filled in, the trial’s response is collected from the keyboard: a matching key press records that key’s name as the response and ends the trial. Setting keyboard also switches the trial away from the default response mode (typing an answer or clicking the stimulus) to key presses instead, unless responseType is one of slider, box, comment. On instruction-type screens, filling in keyboard lets participants advance with a key press and hides the NEXT button that would otherwise appear.

Put the key you want to accept in the cell, for example space. To offer a choice between keys, list them separated by spaces: left right, f j, y n.

Values are case-insensitive, and any run of characters that is not a letter, a digit or + acts as a separator, so a b, a,b, a;b and a&b are all the same list.

The keys you can name:

  • Single letters and digits: a to z, 0 to 9. Digits also accept the matching numpad key.
  • Named keys: space, enter, escape, and the arrows left, right, up, down.
  • Modifiers as response keys: shift, ctrl, alt, optionally restricted to one side by gluing it on: shiftleft, shiftright, ctrlleft, ctrlright, altleft, altright.
  • Combinations: a modifier (optionally sided) plus + plus one ordinary key, for example alt+a, ctrl+space, altleft+b. Only the modifier can be restricted to a side. Spaces around the + are ignored, so alt + a also works.
  • all: accepts any letter, digit or named key. Modifier keys are deliberately not included in all.

How presses are matched:

  • A plain key only counts when no modifier is held, so a, alt+a and ctrl+a are three different responses.
  • A combination needs its modifier held down, on the required side if you specified one.
  • A modifier listed on its own counts as soon as it is pressed, whatever else is held. This is deliberate, so that AltGr layouts still work.

The response recorded in the results is the token that matched, for example a, space, alt, altright or alt+a.

Value / tokenMeaning
empty cellNo keyboard responses (default; but see Tips & gotchas)
azSingle letter key (case-insensitive)
09Digit key, top row or numpad
space, enter, escapeNamed special keys
left, right, up, downArrow keys
shift, ctrl, altModifier key as a response key
shiftleft/right, ctrlleft/right, altleft/rightSide-specific modifier as response key
<mod>+<key> e.g. alt+a, ctrlright+2Combination: modifier held while key pressed
all (anywhere in the value)Any letter, digit or named key is a valid response; the response is the key’s name
multiple tokens separated by any non-alphanumeric charactersList of alternatives, e.g. a,l / a l / a;l

Leave the column out of the trial file, or leave a cell empty, and that trial accepts no keyboard responses at all: key presses are ignored and cannot end the trial.

A trial counts as a keyboard trial as soon as its keyboard cell has any value.

On test and practice trials with keyboard empty and no button1, clicking the stimulus becomes the response instead.

  • responseType: keyboard responses are ignored when responseType is slider, box or comment. Other response types (for example label or clicks) work alongside keyboard keys.
  • responseType mic: keys stay active during a microphone recording, but a press does not cut the recording short. The recording is finished first, then the key you pressed is stored as the trial’s response with the audio intact.
  • responseOptions min:N / max:N: lets the participant press several keys in one trial. The pressed keys are recorded joined with ;, a Confirm button appears once min presses have been made, and the trial ends automatically at max. The reaction time of each individual press goes to the RTkeys results column.
  • key: the recorded key token (for example a) is compared against the key column to score the trial as correct or incorrect.
  • responseWindow with a min: duration: while the minimum window is still open, the participant’s last key press is held back and only submitted when the window closes.
  • Instructions screens: filling in keyboard lets participants advance with a key press, and with presTime set to 0 it also hides the default NEXT button.
  • ALT keys: as soon as any token uses alt, the browser’s own ALT behavior (menu focus, shortcuts) is suppressed for the trial.
  • Multiplayer chat: key responses are suspended while a chat is in progress, so typing a message cannot end a trial.
typestim1keyboardkeypresTime
testword_olda la2000

Two-alternative response: press A or L; A is correct.

typestim1keyboardresponseOptions
testrecall_promptallmin:3;max:5

Any letter/digit/named key accepted; participant must press at least 3 keys, at most 5; responses recorded as k1;k2;k3.

typestim1keyboard
testbilateral_taskaltleft altright

Left ALT vs right ALT as the two response keys; response recorded as altleft or altright.

Most real trials use the simplest forms these examples generalize. A single key, or space-separated single keys:

typestim1keyboardkey
testgo_signalspacespace
testpairleft rightleft

space alone, and space-separated pairs like left right / y n / f j, are the dominant real patterns.

  • There is no any keyword. Writing any gives you the three separate keys a, n and y.
  • Names that are not recognized fall apart into single letters: arrowleft becomes the keys a, r, o and w plus left. Use left, right, up and down for the arrow keys.
  • A plain key does not match while a modifier is held, so with keyboard set to a, pressing SHIFT+A registers nothing.
  • A modifier listed on its own matches even when another modifier is held. This is intentional, because AltGr is reported as CTRL+ALT.
  • For sided combinations, the side that counts is the side of the modifier the participant is actually holding.

keyboard appears in these worked recipes:

  • Replayed random order: Shuffle a block once, then replay that exact order in a later block so both passes share identical order effects.
  • Adaptive staircase: Home in on a participant’s detection threshold by making trials harder after correct answers and easier after misses.
  • Between-subject conditions: Give each participant one of two stimulus sets, while shared screens run for everyone.
  • Go/no-go task: Score a press as correct on go trials and a withheld response as correct on no-go trials.
  • Nested block shuffle: Randomise the order of whole task sections and of the mini-blocks inside each section, keeping every block’s trials together.