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 (so you don't need to set property end unless you want it to end earlier).

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 then set elements in the trial to start/end from trigger (element properties start/end fields trigger/triggerBy). You can also set later trials to start at fixed times from trigger (trial object property start).

Response/Trigger values generated are key numbers. Key numbers depend on your operating system. Function KbShow is a quick way to find them. See also Psychtoolbox KbName.

For each trial you define in an experiment script, you can make one or more 

keyPress

 objects using 

keyPress

Object and input them to addTrial.

For each trial you define in an experiment script, you can make one or more 

keyPress

 objects using 

keyPress

Object and input them to addTrial.

Input properties

Adjustable properties

You can allow the subject to adjust the following input properties of an object of this type during the experiment using an adjuster element. If you need to make other properties adjustable, you can copy the element type using newPbType and edit it.

position
nn_eyes
rotation
opacity

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

nn_listenKeys
nn_ignoreKeys

Default: listen to all keys

nn_listenKeys is a row vector of key numbers 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.

useQueue

Default: use keyboard queue

<cd>true<cd>/<cd>false<cd>: There are two methods a keyPress element can use to get inputs: logging key presses with time stamps in a "keyboard queue" as they occur (<cd>true<cd>), or directly checking key up/down states once per frame (<cd>false<cd>). Direct checking has disadvantages: at least in principle it can miss a key up-down-up transition that is shorter than one frame (e.g. ≈17 msec at 60 frames/sec, but longer if your system drops frames due to load). Also its time measurement resolution is limited by frame rate (±1/2 frame interval, e.g. ≈8 msec). On the other hand, the only disadvantage to a keyboard queue is that you will get an error if two elements try to use a queue for the same device at the same time. So, generally leave useQueue = default <cd>true<cd> unless you're in that unusual case. ALWAYS leave useQueue = <cd>true<cd> if listening for a trigger signal where missing it could hang your experiment.

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.