Mouse responses
Mouse responses are collected with the mouse_response item. The mouse_response is primarily intended to collect individual mouse clicks. If you want to collect mouse-cursor trajectories, take a look at the mousetrap plugins:
Response variables
The mouse_response sets the standard response variables as described here:
Mouse-button names
Mouse buttons have a number (1
, etc.) as well as a name (left_button
, etc.). Both can be used to specify correct and allowed responses, but the response
variable will be set to a number.
left_button
corresponds to1
middle_button
corresponds to2
right_button
corresponds to3
scroll_up
corresponds to4
scroll_down
corresponds to5
Correct response
The Correct response field indicates which response is considered correct. After a correct response, the correct
variable is automatically set to 1; after an incorrect response or a timeout (i.e. everything else), correct
is set to 0; if no correct response is specified, correct
is set to 'undefined'.
You can indicate the correct response in three main ways:
- Leave the field empty. If you leave the Correct response field empty, OpenSesame will automatically check if a variable called
correct_response
has been defined, and, if so, use this variable for the correct response. - Enter a literal value. You can explicitly enter a response, such as 1. This is only useful if the correct response is fixed.
- Enter a variable name. You can enter a variable, such as '{cr}'. In this case, this variable will be used for the correct response.
Note that the correct response refers to which mouse button was clicked, not to which region of interest was clicked (ROI); see the section below for more information about ROIs.
Allowed responses
The Allowed responses field indicates a list of allowed responses. All other responses will be ignored, except for 'Escape', which will pause the experiment. The allowed responses should be a semicolon-separated list of responses, such as '1;3' to allow the left and right mouse buttons. To accept all responses, leave the Allowed responses field empty.
Note that the allowed responses refer to which mouse button can be clicked, not to which region of interest can be clicked (ROI); see the section below for more information about ROIs.
Timeout
The Timeout field indicates a timeout value in milliseconds, or 'infinite' for no timeout. When a timeout occurs, the following happens:
response_time
is set to the timeout value, or rather to the time it takes for a timeout to be registered, which may deviate slightly from the timeout value.response
is set to 'None'. This means that you can specify 'None' for the correct response a timeout should occur; this can be useful, for example, in a go/no-go task, when the participant should withold a response on no-go trials.
Coordinates and regions of interest (ROIs)
The cursor_x
and cursor_y
variables hold the location of the mouse click.
If you indicate a linked sketchpad, the variable cursor_roi
will hold a comma-separated list of names of elements that contain the clicked coordinate. In other words, elements on the sketchpad automatically serve as regions of interest for the mouse click.
If the correctness of a response depends on which ROI was clicked, you cannot use the correct_response
variable for this, because this currently refers only to which mouse button was clicked. Instead you need to use a simple script.
In a Python inline_script you can do this as follows:
clicked_rois = cursor_roi.split(';')
correct_roi = 'my_roi'
if correct_roi in clicked_rois:
print('correct!')
correct = 1
else:
print('incorrect!')
correct = 0
With OSWeb using a inline_javascript you can do this as follows:
clicked_rois = cursor_roi.split(';')
correct_roi = 'my_roi'
if (clicked_rois.includes(correct_roi)) {
console.log('correct!')
correct = 1
} else {
console.log('incorrect!')
correct = 0
}
Collecting mouse responses in Python
You can use the mouse
object to collect mouse responses in Python: