Update User or Animal response: links & code authored by Fabian Berg's avatar Fabian Berg
This chapter contains functions you can use to record the participant’s or the animal’s behavioral responses using either response keys or a touchscreen. The function keyBuffer will be of major importance for behavioral recordings in most experiments.
This chapter contains functions you can use to record the participant’s or the animal’s behavioral responses using either response keys or a touchscreen. The function [keyBuffer](/User-or-animal-response#keybuffer-animal) will be of major importance for behavioral recordings in most experiments.
[[_TOC_]]
## getKeyValue
function: getKeyValue
function: [getKeyValue](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Tools/getKeyValue.m)
**Description**
Use this function to get the key values used for getAnswer. Simply start the program and when ready press a key. The program will give you the internal code for this key. Not a function that should be called during an experiment but during preparation.
Use this function to get the key values used for [getAnswer](/User-or-animal-response#getanswer-human). Simply start the program and when ready press a key. The program will give you the internal code for this key. Not a function that should be called during an experiment but during preparation.
**See also**
getAnswer
[getAnswer](/User-or-animal-response#getanswer-human)
## keyBuffer (animal)
function: total = keyBuffer(duration,varargin)
function: total = [keyBuffer(duration,varargin)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/IO/keyBuffer.m)
**Description**
This buffer stores behavioral responses over a period of time specified in duration. In addition, it terminates if a specified number of responses on "good keys", "neutral keys" or "bad keys" is reached.
To use this feature specify at least the position of the good, neutral or bad keys and the number of responses. This function can be used either with a touchscreen or with input-keys.
It is up to you to determine which responde key is good, neutral or bad key. These differentiations will help you to analyse the response, since the answers are stored separately.
For auditory feedback use the 'sound' option. It plays a previously loaded sound file for every response.
It is up to you to determine which response key is good, neutral or bad key. These differentiations will help you to analyse the response, since the answers are stored separately.
For auditory feedback use the 'sound' option. It plays a [previously loaded sound file](/Sound-options#loadsound) for every response.
**Inputs**
~~~
......@@ -29,16 +29,16 @@ For auditory feedback use the 'sound' option. It plays a previously loaded sound
**Inputs-optional**
~~~
varargin goodKey followed by a vector of pin numbers and a scalar of response amount
badKey followed by a vector of pin numbers and a scalar of response amount
neutralKey followed by a vector of pin numbers and a scalar of response amount
timeoutBad increase the waiting duration for each response to a bad key.
varargin 'goodKey' followed by a vector of pin numbers and a scalar of response amount
'badKey' followed by a vector of pin numbers and a scalar of response amount
'neutralKey' followed by a vector of pin numbers and a scalar of response amount
'timeoutBad' increase the waiting duration for each response to a bad key.
Needs to be followed by a specified time in sec
sound sound that will be played every time an answer is given.
'sound' sound that will be played every time an answer is given.
Needs to be followed by a wav file handle, loaded with loadSound
remoteStop a remote computer can interrupt the execution via network.
'remoteStop' a remote computer can interrupt the execution via network.
You can also use the stopRemoteKeyBuffer function.
sendNetID send the clients network ID after a *successful* response to a control computer (network init required)
'sendNetID' send the clients network ID after a *successful* response to a control computer (network init required)
~~~
**Outputs**
......@@ -58,16 +58,16 @@ For auditory feedback use the 'sound' option. It plays a previously loaded sound
~~~
**Examples**
~~~
1. total = keyBuffer(10, goodKey, [1 2], 3);
~~~matlab
1. total = keyBuffer(10, 'goodKey', [1 2], 3);
% keyBuffer terminates after 10 seconds OR after three responses on keys at position
% 1 or 2
2. total = keyBuffer(10, badKey, [3 4], 8, goodKey, [1 2], 3);
2. total = keyBuffer(10, 'badKey', [3 4], 8, 'goodKey', [1 2], 3);
% keyBuffer terminates after 10 seconds OR after three responses on keys at position
% 1 or 2 OR after eight responses on keys at position 3 or 4
3. total = keyBuffer(4, badKey, 3, 3, goodKey, [1 2], 3, sound, soundH);
3. total = keyBuffer(4, 'badKey', 3, 3, 'goodKey', [1 2], 3, 'sound', soundH);
% keyBuffer terminates after 4 seconds OR after three responses on keys at position 1
% or 2 OR after three responses on key at position 3. In addition every answer is
% rewarded with a sound that was loaded with loadSound and saved into the variable
......@@ -75,14 +75,14 @@ For auditory feedback use the 'sound' option. It plays a previously loaded sound
~~~
**See also**
switchBuffer, touchBuffer, bIO, getAnswer
[switchBuffer](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/IO/switchBuffer.m), [touchBuffer](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Touchscreen/touchBuffer.m), [bIO](/Device-interface#bio), [getAnswer](/User-or-animal-response#getanswer-human)
## getAnswer (human)
function: total = getAnswer(duration,varargin)
function: total = [getAnswer(duration,varargin)](/User-or-animal-response#getanswer-human)
**Description**
Use this function to get access to the user’s response keys in human experiments and the keyboard option. It is more flexible to use and replaces the function keyBuffer in most human experiments. getAnswer allows the ESC Key to be pressed to cancel the user input.
Use this function to get access to the user’s response keys in human experiments and the keyboard option. It is more flexible to use and replaces the function [keyBuffer](/User-or-animal-response#keybuffer-animal) in most human experiments. getAnswer allows the ESC Key to be pressed to cancel the user input.
**Inputs**
~~~
......@@ -91,13 +91,13 @@ Use this function to get access to the user’s response keys in human experimen
**Inputs-Optional**
~~~
varargin goodKey followed by a vector of keyboard values and a scalar of response amount
badKey followed by a vector of keyboard values and a scalar of response amount
anyKey without argument, waits the given time and continues if the user pressed any key.
varargin 'goodKey' followed by a vector of keyboard values and a scalar of response amount
'badKey' followed by a vector of keyboard values and a scalar of response amount
'anyKey' without argument, waits the given time and continues if the user pressed any key.
Not to be used with 'goodKey' or 'badKey'
waitAnyway waits the given time, even if the user pressed a key
'waitAnyway' waits the given time, even if the user pressed a key
(reaction time is saved in the extra field rt)
wait4release without argument, waits until the key is released.
'wait4release' without argument, waits until the key is released.
Bad for exact timing, but necessary in some cases
~~~
......@@ -118,25 +118,27 @@ Use this function to get access to the user’s response keys in human experimen
~~~
**Examples**
~~~
~~~matlab
1) out = getAnswer(10, 'goodKey', 65);
Waits 10 seconds or continues after the user presses key a (65 represents kay a). All other keys are ignored
% Waits 10 seconds or continues after the user presses key a (65 represents kay a).
% All other keys are ignored
2) out = getAnswer(5, 'goodKey', 77, 'badKey', [74 75]);
Waits 5 seconds or continues after a button press on m (77 as goodKey) or j and k (74, 75 as badKeys).
The result struct marks answer as incorrect (-1) if button j or k were pressed and correct (1) if button m was pressed
% Waits 5 seconds or continues after a button press on m (77 as goodKey) or j and k (74, 75 as badKeys).
% The result struct marks answer as incorrect (-1) if button j or k were pressed and correct (1) if button m was pressed
3) out = getAnswer(10, 'anyKey');
Waits 10 seconds or continues after a button press on any key. To test this feature in the command line use the following code:
WaitSecs(0.2);getAnswer(5, 'anyKey')
% Waits 10 seconds or continues after a button press on any key.
% To test this feature in the command line use the following code:
% WaitSecs(0.2);getAnswer(5, 'anyKey')
~~~
## createButton
function: bHand = createButton(text, varargin)
function: bHand = [createButton(text, varargin)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Screen/createButton.m)
**Description**
Creates a ‘button’ on the stimulus window. Position defines the left upper corner of the ‘button’. The function actually only creates text similar to showText with a box around it. To activate this ‘button’ on the screen use the getButtonClick function.
Creates a ‘button’ on the stimulus window. Position defines the left upper corner of the ‘button’. The function actually only creates text similar to [showText](/Text-options#showtext) with a box around it. To activate this ‘button’ on the screen use the [getButtonClick](/User-or-animal-response#getbuttonclick) function.
**Inputs**
~~~
......@@ -145,15 +147,15 @@ Creates a ‘button’ on the stimulus window. Position defines the left upper c
**Inputs-optional**
~~~
varargin ‘x’ x position in percent (0 -> left, 100 -> right)
‘y’ y position in percent (0 -> top, 100 -> bottom)
color text color as RGB vector with values from 0:255
size text size in pixel
dontFlip don't flip buffers (advanced users)
varargin 'x' x position in percent (0 -> left, 100 -> right)
'y' y position in percent (0 -> top, 100 -> bottom)
'color' text color as RGB vector with values from 0:255
'size' text size in pixel
'dontFlip' don't flip buffers (advanced users)
~~~
**Examples**
~~~
~~~matlab
1. buttonPos = createButton('Okay', 'x', 10, 'y', 10);
% displays a button with text "Okay" in the left upper corner
......@@ -166,14 +168,14 @@ Creates a ‘button’ on the stimulus window. Position defines the left upper c
~~~
**See also**
getMouse, showText, keyBuffer, getButtonClick
[getMouse](/User-or-animal-response#getmousepos), [showText](/Text-options#showtext), [keyBuffer](/User-or-animal-response#keybuffer-animal), [getButtonClick](/User-or-animal-response#getbuttonclick)
## getButtonClick
function: out = getButtonClick(stopTime, varargin)
function: out = [getButtonClick(stopTime, varargin)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/IO/getButtonClick.m)
**Description**
Get the click on a button that was created with createButton. Function ends after specified time, after button click or after ESC was clicked to exit the function.
Get the click on a button that was created with [createButton](/User-or-animal-response#createbutton). Function ends after specified time, after button click or after ESC was clicked to exit the function.
**Inputs**
~~~
......@@ -194,17 +196,17 @@ Get the click on a button that was created with createButton. Function ends afte
~~~
**Examples**
~~~
~~~matlab
1. out = getButtonClick(5, bHand1, bHand2, bHand3);
% Waits 5 seconds or until a click on any of the buttons occurs
~~~
## getMousePos
function: out = getMousePos(waitTime)
function: out = [getMousePos(waitTime)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/IO/getMousePos.m)
**Description**
This function returns the Mouse position (x, y) after a left click on the stimulus presentation window. Calling getMousePos without arguments blocks execution until a click is done. A call with the argument waitTime exits after a left click or after the given time.
This function returns the Mouse position (x, y) after a left click on the stimulus presentation window. Calling [getMousePos](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/IO/getMousePos.m) without arguments blocks execution until a click is done. A call with the argument waitTime exits after a left click or after the given time.
**Inputs-Optional**
~~~
......
......