A response handler element that records subject response by key press. Also works with other keyboard-like devices. At default waits for one press of any key, then records response and ends on its own.

Response values generated are key numbers. Key numbers depend on your operating system. The little tool KbShow is an easy way to find them at the MATLAB command line. See also Psychtoolbox KbName.

You can also use keyPress elements to listen for trigger signals from an external device like a scanner that arrive as keyboard inputs. To do this set registerTrigger = <cd>true<cd> to register inputs as triggers instead of responses from subject. You can set elements in the same trial to start/end from either responses or triggers (element properties start/end). However, for triggers you can also set later trials to start at fixed times from trigger with zero drift (trial object property start).

▸ Ends on its own?

By default yes, when it records one response. You can change number of responses to wait for in property maxNumResponses. If you set maxNumResponses = <cd>inf<cd>, records responses indefinitely until a condition you set in property end.

If an element can end on its own, you don't need to set end conditions for it in property end (unless you want it to maybe end earlier).

No—runs until a condition you set in property end.

Input properties

Adjustable properties

You can vary or allow the subject to adjust the following input properties of an object of this type in real time when it's running. If you need to make other properties adjustable, you can edit the element type code—see Element Type Programming Manual.





Default: default device, generally the keyboard

<cd>[]<cd> = default device according to Psychtoolbox, which is generally the keyboard. Usually this is all you need to know.

Optionally you can listen for input from some other keyboard-like device. n_device is HID device number to listen to. You can use Psychtoolbox functions GetKeyboardIndices or PsychHID('Devices') to see available device numbers. A keyPress element uses Psychtoolbox KbQueueCreate if useQueue below = <cd>true<cd>, or KbCheck if useQueue = <cd>false<cd>. n_device goes to the input of one of those functions. See help for these functions if you need more information on device numbers.


Default: listen to all keys

nn_listenKeys is a row vector of key numbers (see above) to listen to. <cd>[]<cd> = all.

nn_ignoreKeys is a row vector of key numbers to ignore. <cd>[]<cd> = none. If you leave nn_listenKeys = <cd>[]<cd>, you can listen to all keys except the ones you specify in nn_ignoreKeys.

Note this is before responses are received, so these are always key numbers, even if you use property translateResponse to record responses as other values.


Default: use keyboard checking for responses, queueing for triggers

<cd>true<cd>/<cd>false<cd>: There are two methods a keyPress element can use to get inputs: continuously listening for key presses in the background and logging them in a "queue" to be retrieved once per frame (<cd>true<cd>), or directly checking key up/down states once per frame (<cd>false<cd>). The checking method is simpler and has some minor advantages, but it can miss inputs that are so brief that they last (key is down) less than one frame (e.g. ≈ 17 msec at 60 frames/sec, but longer if your system drops frames due to load). The queueing method may have slightly better time measurement precision and never misses an input. Checking is usually sufficient for responses. Queueing is better for triggers from devices (registerTrigger = <cd>true<cd>) where missing a trigger could hang your experiment.

<cd>[]<cd> (default) = use checking for responses, queueing for triggers.

Input properties all visual elements have


Input properties all adjuster elements have


Input properties all objects have


Record properties

PsychBench uses record properties to record information during experiments. You can't set record properties but you can see them in experiment results by listing them input property report.