keyPress

 element objects

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 on any attached keyboard, then records response and ends on its own. Response values generated are numbers corresponding to keys pressed—see property listenKeyNames below.

You can also use keyPress elements to listen for synchronization 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, and n_device below to specify the device to listen to. Most commonly then set syncExperiment = <cd>true<cd> to tell the element to synchronize the experiment at trigger. You can then set the timing of any element in the trial (element properties start/end field t_sync) and/or subsequent trial timing (trial object property start field t_sync) from sync.

See also textInput elements.

▸ Object ends on its own?

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

"Ends on its own" means ends automatically at that point. 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 any condition you set in property end.

Input properties
Record properties
keyPress
elements (see below)

listenKeyNames
ignoreKeyNames
n_device
useQueue

All visual elements
position

All adjuster elements have
adjust

All response handler elements
translateResponse
scoreResponse
correctResponse
scoreResponseForStaircase

maxNumResponses
recordDefaultResponse
registerTrigger
autoResponse
autoResponseLatency

All elements
start
end

startBuffer
endBuffer

syncExperiment
vary
staircase

All objects
report
info

listenKeyNames

Default: listen to all keys; response values are operating system-dependent key numbers

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 see all key names).

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. You can also use showKey to see 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 at default = listen to all keys, response values are just the operating system-dependent key numbers.

ignoreKeyNames

Default: don't ignore any keys

Like listenKeyNames above except keys to ignore. If you leave listenKeyNames at default, you can listen to all keys except the ones you list here.

n_device

Default: listen to all attached keyboards if you leave registerTrigger and useQueue at default, else default keyboard

If you want to narrow down which device to listen to, you can set a HID device number here. Use Psychtoolbox functions GetKeyboardIndices or PsychHID('Devices') to see available device numbers.

Note if you set registerTrigger or useQueue below = <cd>true<cd> then a keyPress element can only listen to one device and default becomes the single default keyboard according to Psychtoolbox. In this case if that device is not what you want, you must specify the device you want here.

useQueue

Default: use polling if you leave registerTrigger at default, else keyboard queue

At default a keyPress element uses polling by Psychtoolbox KbCheck. If you set registerTrigger = <cd>true<cd>, it uses a keyboard queue (Psychtoolbox KbQueueCreate, etc.) instead. In unusual cases you may want to override these defaults by setting useQueue = <cd>true<cd>/<cd>false<cd>.

Adjustable properties

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

Adjustable properties

Adjustable properties

position
nn_eyes
rotation
colorMask
alpha
intensity
contrastMult
drawCodeVars

(None)

(None)

Input properties
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 using input property report.

keyPress
elements (see below)

All response handler elements
response
responseScore
responseTime
responseLatency
d_responseTime
numResponses

All elements
startTime
endTime
duration
n_startFrame
n_endFrame
startLatencyBufferable
endLatencyBufferable

trigger
triggerTime
d_triggerTime
numTriggers

syncTime