keyPress

 elements

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 numbers corresponding to keys you list in property listenKeyNames, or operating system-depending key numbers if you don't set it.

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).

See also textInput elements.

▸ Object 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.

position
nn_eyes
rotation
colorMask
alpha
intensity
contrastMult
drawCodeVars

(None)

(None)

n_device

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.

listenKeyNames

Default: listen to all keys; response values are key numbers on your operating system

An array of strings that are names of keys to listen to. All other keys are ignored. Key names are common across operating systems. To get them you can use the tool showKey at the MATLAB command line (type help showKey for usage, but basically press a key to see its name or use inputs to get all key names). <cd>[]<cd> = listen to all keys.

Alternatively you can set this property to a vector of numbers that are key numbers. These are the same as used by Psychtoolbox functions like KbCheck. Note key numbers are different across operating systems. showKey also shows key numbers.

Either way, response values generated by the keyPress element are numbers corresponding to the order of the keys you list in this property. e.g. listenKeyNames = <cd>[<cd><cds>"left" "right"<cds><cd>]<cd> → response value 1 = left arrow key, 2 = right arrow key. Or if you leave listenKeyNames = <cd>[]<cd> to listen to all keys then response values are just the operating system-dependent key numbers.

ignoreKeyNames

Like listenKeyNames above except keys to ignore. If you leave listenKeyNames = <cd>[]<cd>, you can listen to all keys except the ones you list here. This doesn't affect response values. <cd>[]<cd> = ignore no keys.

useQueue

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

position

Input properties all adjuster elements have

adjust

Input properties all objects have

report
info

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.