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.
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.
function: total = [keyBuffer(duration,varargin)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/IO/keyBuffer.m)
**Description**
**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.
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.
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.
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 for every response.
For auditory feedback use the 'sound' option. It plays a [previously loaded sound file](/Sound-options#loadsound) for every response.
**Inputs**
**Inputs**
~~~
~~~
...
@@ -29,16 +29,16 @@ For auditory feedback use the 'sound' option. It plays a previously loaded sound
...
@@ -29,16 +29,16 @@ For auditory feedback use the 'sound' option. It plays a previously loaded sound
**Inputs-optional**
**Inputs-optional**
~~~
~~~
varargin ‘goodKey’ followed by a vector of pin numbers and a scalar of response amount
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
'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
'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.
'timeoutBad' increase the waiting duration for each response to a bad key.
Needs to be followed by a specified time in sec
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
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.
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**
**Outputs**
...
@@ -58,16 +58,16 @@ For auditory feedback use the 'sound' option. It plays a previously loaded sound
...
@@ -58,16 +58,16 @@ For auditory feedback use the 'sound' option. It plays a previously loaded sound
~~~
~~~
**Examples**
**Examples**
~~~
~~~matlab
1. total = keyBuffer(10, ‘goodKey’, [1 2], 3);
1.total=keyBuffer(10,'goodKey',[12],3);
% keyBuffer terminates after 10 seconds OR after three responses on keys at position
% keyBuffer terminates after 10 seconds OR after three responses on keys at position
function: total = [getAnswer(duration,varargin)](/User-or-animal-response#getanswer-human)
**Description**
**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**
**Inputs**
~~~
~~~
...
@@ -91,13 +91,13 @@ Use this function to get access to the user’s response keys in human experimen
...
@@ -91,13 +91,13 @@ Use this function to get access to the user’s response keys in human experimen
**Inputs-Optional**
**Inputs-Optional**
~~~
~~~
varargin ‘goodKey’ followed by a vector of keyboard values and a scalar of response amount
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
'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.
'anyKey' without argument, waits the given time and continues if the user pressed any key.
Not to be used with 'goodKey' or 'badKey'
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)
(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
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
...
@@ -118,25 +118,27 @@ Use this function to get access to the user’s response keys in human experimen
~~~
~~~
**Examples**
**Examples**
~~~
~~~matlab
1)out=getAnswer(10,'goodKey',65);
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',[7475]);
2)out=getAnswer(5,'goodKey',77,'badKey',[7475]);
Waits 5 seconds or continues after a button press on m (77 as goodKey) or j and k (74, 75 as badKeys).
% 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
% 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');
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:
% Waits 10 seconds or continues after a button press on any key.
WaitSecs(0.2);getAnswer(5, 'anyKey')
% To test this feature in the command line use the following code:
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**
**Inputs**
~~~
~~~
...
@@ -145,15 +147,15 @@ Creates a ‘button’ on the stimulus window. Position defines the left upper c
...
@@ -145,15 +147,15 @@ Creates a ‘button’ on the stimulus window. Position defines the left upper c
**Inputs-optional**
**Inputs-optional**
~~~
~~~
varargin ‘x’ x position in percent (0 -> left, 100 -> right)
varargin 'x' x position in percent (0 -> left, 100 -> right)
‘y’ y position in percent (0 -> top, 100 -> bottom)
'y' y position in percent (0 -> top, 100 -> bottom)
‘color’ text color as RGB vector with values from 0:255
'color' text color as RGB vector with values from 0:255
‘size’ text size in pixel
'size' text size in pixel
‘dontFlip’ don't flip buffers (advanced users)
'dontFlip' don't flip buffers (advanced users)
~~~
~~~
**Examples**
**Examples**
~~~
~~~matlab
1.buttonPos=createButton('Okay','x',10,'y',10);
1.buttonPos=createButton('Okay','x',10,'y',10);
% displays a button with text "Okay" in the left upper corner
% 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
...
@@ -166,14 +168,14 @@ Creates a ‘button’ on the stimulus window. Position defines the left upper c
function: out = getButtonClick(stopTime, varargin)
function: out = [getButtonClick(stopTime, varargin)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/IO/getButtonClick.m)
**Description**
**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**
**Inputs**
~~~
~~~
...
@@ -194,17 +196,17 @@ Get the click on a button that was created with createButton. Function ends afte
...
@@ -194,17 +196,17 @@ Get the click on a button that was created with createButton. Function ends afte
~~~
~~~
**Examples**
**Examples**
~~~
~~~matlab
1.out=getButtonClick(5,bHand1,bHand2,bHand3);
1.out=getButtonClick(5,bHand1,bHand2,bHand3);
% Waits 5 seconds or until a click on any of the buttons occurs
% Waits 5 seconds or until a click on any of the buttons occurs
~~~
~~~
## getMousePos
## getMousePos
function: out = getMousePos(waitTime)
function: out = [getMousePos(waitTime)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/IO/getMousePos.m)
**Description**
**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.