standardize ALL_KEYS and NO_KEYS (#252)

This commit is contained in:
Josh de Leeuw 2016-06-30 13:20:34 -04:00
parent 6d8b877987
commit 3b910469d3
14 changed files with 82 additions and 26 deletions

View File

@ -12,7 +12,7 @@ stimuli | array | *undefined* | Each element of the array is a path to an image
frame_time | numeric | 250 | How long to display each image (in milliseconds).
frame_isi | numeric | 0 | If greater than 0, then a gap will be shown between each image in the sequence. This parameter specifies the length of the gap.
sequence_reps | numeric | 1 | How many times to show the entire sequence. There will be no gap (other than the gap specified by `frame_isi`) between repetitions.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
choices | array of keycodes | `jsPsych.ALL_KEYS` | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of `jsPsych.ALL_KEYS` means that all keys will be accepted as valid responses. Specifying `jsPsych.NO_KEYS` will mean that no responses are allowed.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).

View File

@ -10,7 +10,7 @@ Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a path to an image file.
key_answer | numeric | *undefined* | A [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) indicating the correct response.
choices | array | *undefined* | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`).
choices | array of keycodes | `jsPsych.ALL_KEYS` | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of `jsPsych.ALL_KEYS` means that all keys will be accepted as valid responses. Specifying `jsPsych.NO_KEYS` will mean that no responses are allowed.
text_answer | string | "" | A text label that describes the correct answer. Used in conjunction with the `correct_text` and `incorrect_text` parameters.
correct_text | string | "Correct." | String to show when the correct answer is given. Can contain HTML formatting. The special string `%ANS%` can be used within the string. If present, the plugin will put the `text_answer` for the trial in place of the %ANS% string (see example below).
incorrect_text | string | "Wrong." | String to show when the wrong answer is given. Can contain HTML formatting. The special string `%ANS%` can be used within the string. If present, the plugin will put the `text_answer` for the trial in place of the %ANS% string (see example below).

View File

@ -11,7 +11,7 @@ Parameter | Type | Default Value | Description
stimulus | string | *undefined* | The stimulus to display. Either HTML-formatted, or the path to an image.
is_html | boolean | false | If `stimulus` is an HTML-formatted string, this parameter needs to be set to `true`.
key_answer | numeric | *undefined* | The [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) indicating the correct response.
choices | array | *undefined* | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`).
choices | array of keycodes | `jsPsych.ALL_KEYS` | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of `jsPsych.ALL_KEYS` means that all keys will be accepted as valid responses. Specifying `jsPsych.NO_KEYS` will mean that no responses are allowed.
text_answer | string | "" | A label that is associated with the correct answer. Used in conjunction with the `correct_text` and `incorrect_text` parameters.
correct_text | string | "Correct." | String to show when the correct answer is given. Can contain HTML formatting. The special string `%ANS%` can be used within the string. If present, the plugin will put the `text_answer` for the trial in place of the %ANS% string (see example below).
incorrect_text | string | "Wrong." | String to show when the wrong answer is given. Can contain HTML formatting. The special string `%ANS%` can be used within the string. If present, the plugin will put the `text_answer` for the trial in place of the %ANS% string (see example below).

View File

@ -13,7 +13,7 @@ This table lists the parameters associated with this plugin. Parameters with a d
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimulus | string | *undefined* | Path to an audio file.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
choices | array of keycodes | `jsPsych.ALL_KEYS` | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of `jsPsych.ALL_KEYS` means that all keys will be accepted as valid responses. Specifying `jsPsych.NO_KEYS` will mean that no responses are allowed.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed on the screen. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
response_ends_trial | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.

View File

@ -12,7 +12,7 @@ Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimulus | string | *undefined* | The stimulus to display. Either HTML-formatted, or the path to an image.
is_html | boolean | false | If `stimulus` is an HTML-formatted string, this parameter needs to be set to `true`.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
choices | array of keycodes | `jsPsych.ALL_KEYS` | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of `jsPsych.ALL_KEYS` means that all keys will be accepted as valid responses. Specifying `jsPsych.NO_KEYS` will mean that no responses are allowed.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.

View File

@ -19,7 +19,7 @@ canvas_size | array | `[400, 400]` | Array specifying the width and height of th
image_size | array | `[100, 100]` | Array specifying the width and height of the images to show. The occluding rectangle will have a width equal to the width of image_size.
initial_direction | string | "left" | Which direction the stimulus should move first (subsequent directions will alternate). Choices are "left" or "right".
occlude_center | boolean | true | If true, display a rectangle in the center of the screen that is just wide enough to occlude the image completely as it passes behind.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
choices | array of keycodes | `jsPsych.ALL_KEYS` | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of `jsPsych.ALL_KEYS` means that all keys will be accepted as valid responses. Specifying `jsPsych.NO_KEYS` will mean that no responses are allowed.
timing_cycle | numeric | 1000 | How long it takes for a stimulus in the sequence to make a complete cycle (move to the edge and back to the center) in milliseconds.
timing_pre_movement | numeric | 500 | How long to wait before the stimuli starts moving from behind the center rectangle.

View File

@ -30,6 +30,10 @@ var jsPsych = (function() {
// done loading?
var loaded = false;
// enumerated variables for special parameter types
core.ALL_KEYS = 'allkeys';
core.NO_KEYS = 'none';
//
// public methods
//
@ -1400,20 +1404,23 @@ jsPsych.pluginAPI = (function() {
}
var valid_response = false;
if (typeof parameters.valid_responses === 'undefined' || parameters.valid_responses.length === 0) {
if (typeof parameters.valid_responses === 'undefined' || parameters.valid_responses == jsPsych.ALL_KEYS) {
valid_response = true;
}
for (var i = 0; i < parameters.valid_responses.length; i++) {
if (typeof parameters.valid_responses[i] == 'string') {
if (typeof keylookup[parameters.valid_responses[i]] !== 'undefined') {
if (e.which == keylookup[parameters.valid_responses[i]]) {
} else {
if(parameters.valid_responses != jsPsych.NO_KEYS){
for (var i = 0; i < parameters.valid_responses.length; i++) {
if (typeof parameters.valid_responses[i] == 'string') {
if (typeof keylookup[parameters.valid_responses[i]] !== 'undefined') {
if (e.which == keylookup[parameters.valid_responses[i]]) {
valid_response = true;
}
} else {
throw new Error('Invalid key string specified for getKeyboardResponse');
}
} else if (e.which == parameters.valid_responses[i]) {
valid_response = true;
}
} else {
throw new Error('Invalid key string specified for getKeyboardResponse');
}
} else if (e.which == parameters.valid_responses[i]) {
valid_response = true;
}
}
// check if key was already held down

View File

@ -42,7 +42,7 @@ jsPsych.plugins.animation = (function() {
},
choices: {
type: [jsPsych.plugins.parameterType.KEYCODE],
default: [],
default: jsPsych.ALL_KEYS,
no_function: false,
array: true,
description: ''
@ -61,7 +61,7 @@ jsPsych.plugins.animation = (function() {
trial.frame_time = trial.frame_time || 250;
trial.frame_isi = trial.frame_isi || 0;
trial.sequence_reps = trial.sequence_reps || 1;
trial.choices = trial.choices || [];
trial.choices = trial.choices || jsPsych.ALL_KEYS;
trial.prompt = (typeof trial.prompt === 'undefined') ? "" : trial.prompt;
// if any trial variables are functions

View File

@ -30,7 +30,7 @@ jsPsych.plugins["categorize-animation"] = (function() {
},
choices: {
type: [jsPsych.plugins.parameterType.KEYCODE],
default: [],
default: jsPsych.ALL_KEYS,
no_function: false,
array: true,
description: ''
@ -89,6 +89,7 @@ jsPsych.plugins["categorize-animation"] = (function() {
plugin.trial = function(display_element, trial) {
// set default values
trial.choices = trial.choices || jsPsych.ALL_KEYS;
trial.sequence_reps = trial.sequence_reps || 1;
trial.key_answer = trial.key_answer;
trial.text_answer = (typeof trial.text_answer === 'undefined') ? "" : trial.text_answer;

View File

@ -36,7 +36,7 @@ jsPsych.plugins.categorize = (function() {
},
choices: {
type: [jsPsych.plugins.parameterType.KEYCODE],
default: [],
default: jsPsych.ALL_KEYS,
array: true,
no_function: false,
description: ''
@ -113,6 +113,7 @@ jsPsych.plugins.categorize = (function() {
plugin.trial = function(display_element, trial) {
// default parameters
trial.choices = triaul.choices || jsPsych.ALL_KEYS;
trial.text_answer = (typeof trial.text_answer === 'undefined') ? "" : trial.text_answer;
trial.correct_text = (typeof trial.correct_text === 'undefined') ? "<p class='feedback'>Correct</p>" : trial.correct_text;
trial.incorrect_text = (typeof trial.incorrect_text === 'undefined') ? "<p class='feedback'>Incorrect</p>" : trial.incorrect_text;

View File

@ -27,7 +27,7 @@ jsPsych.plugins["single-audio"] = (function() {
choices: {
type: [jsPsych.plugins.parameterType.KEYCODE],
array: true
default: [],
default: jsPsych.ALL_KEYS,
no_function: false,
description: ''
},
@ -61,7 +61,7 @@ jsPsych.plugins["single-audio"] = (function() {
plugin.trial = function(display_element, trial) {
// default parameters
trial.choices = trial.choices || [];
trial.choices = trial.choices || jsPsych.ALL_KEYS;
trial.response_ends_trial = (typeof trial.response_ends_trial === 'undefined') ? true : trial.response_ends_trial;
trial.trial_ends_after_audio = (typeof trial.trial_ends_after_audio === 'undefined') ? false : trial.trial_ends_after_audio;
trial.timing_response = trial.timing_response || -1; // if -1, then wait for response forever

View File

@ -34,7 +34,7 @@ jsPsych.plugins["single-stim"] = (function() {
choices: {
type: [jsPsych.plugins.parameterType.KEYCODE],
array: true,
default: [],
default: jsPsych.ALL_KEYS,
no_function: false,
description: ''
},
@ -74,7 +74,7 @@ jsPsych.plugins["single-stim"] = (function() {
trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial);
// set default values for the parameters
trial.choices = trial.choices || [];
trial.choices = trial.choices || jsPsych.ALL_KEYS;
trial.response_ends_trial = (typeof trial.response_ends_trial == 'undefined') ? true : trial.response_ends_trial;
trial.timing_stim = trial.timing_stim || -1;
trial.timing_response = trial.timing_response || -1;

View File

@ -31,7 +31,7 @@ jsPsych.plugins['vsl-animate-occlusion'] = (function() {
choices: {
type: [jsPsych.plugins.parameterType.KEYCODE],
array: true,
default: [],
default: jsPsych.ALL_KEYS,
no_function: false,
description: ''
},
@ -85,7 +85,7 @@ jsPsych.plugins['vsl-animate-occlusion'] = (function() {
trial.image_size = trial.image_size || [100, 100];
trial.initial_direction = trial.initial_direction || "left";
trial.occlude_center = (typeof trial.occlude_center === 'undefined') ? true : trial.occlude_center;
trial.choices = trial.choices || [];
trial.choices = trial.choices || jsPsych.ALL_KEYS;
trial.timing_pre_movement = (typeof trial.timing_pre_movement === 'undefined') ? 500 : trial.timing_pre_movement;
// if any trial variables are functions

View File

@ -0,0 +1,47 @@
<!doctype html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script src="../jspsych.js"></script>
<script src="../plugins/jspsych-single-stim.js"></script>
<link rel="stylesheet" href="../css/jspsych.css"></link>
<style>
img {
width: 300px;
}
</style>
</head>
<body>
</body>
<script>
var trial_1 = {
stimulus: '<p>All keys</p>',
choices: jsPsych.ALL_KEYS
}
var trial_2 = {
stimulus: '<p>No keys</p>',
timing_response: 2000,
choices: jsPsych.NO_KEYS
}
var node = {
type: 'single-stim',
is_html: true,
timeline: [trial_1, trial_2],
}
jsPsych.init({
timeline: [node],
on_finish: function() {
jsPsych.data.displayData();
},
default_iti: 250
});
</script>
</html>