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

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)

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.

Alternatively <cd>[]<cd> = 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. <cd>[]<cd> = ignore no keys.

n_device

Default: listen to all attached keyboards if you leave registerTrigger = default <cd>false<cd>, else see below

At default a keyPress element listens to all attached keyboards. However, if you set registerTrigger = <cd>true<cd> then it can only listen to one device and the default becomes the single default keyboard according to Psychtoolbox (generally the first/main keyboard). In this case if that device is not what you want, you must specify a device in the form of a HID device number. You can use Psychtoolbox functions GetKeyboardIndices or PsychHID('Devices') to see available device numbers.

useQueue

Default: automatic based on registerTrigger

By default a keyPress element uses polling by Psychtoolbox KbCheck. However, If you set registerTrigger = <cd>true<cd>, it uses a keyboard queue (Psychtoolbox KbQueueCreate, etc.). In unusual cases you may want to override these defaults by setting useQueue = <cd>true<cd>/<cd>false<cd>. Note if you set useQueue = <cd>true<cd> then n_device above always behaves as if registerTrigger = <cd>true<cd>.

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