mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 16:48:12 +00:00
use getKeyboardResponse
This commit is contained in:
parent
62e4d3e9c2
commit
ac0ce67f16
@ -149,9 +149,6 @@
|
|||||||
display_element.append(trial.prompt);
|
display_element.append(trial.prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// start measuring response time
|
|
||||||
var startTime = (new Date()).getTime();
|
|
||||||
|
|
||||||
// if timing_ab is > 0, then we hide the stimuli after timing_ab milliseconds
|
// if timing_ab is > 0, then we hide the stimuli after timing_ab milliseconds
|
||||||
if (trial.timing_ab > 0) {
|
if (trial.timing_ab > 0) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@ -162,52 +159,54 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the function that triggers when a key is pressed.
|
// create the function that triggers when a key is pressed.
|
||||||
var resp_func = function(e) {
|
var after_response = function(info) {
|
||||||
var flag = false; // true when a valid key is chosen
|
|
||||||
var correct = false; // true when the correct response is chosen
|
var correct = false; // true when the correct response is chosen
|
||||||
if (e.which == trial.left_key) // 'q' key by default
|
|
||||||
|
if (info.key == trial.left_key) // 'q' key by default
|
||||||
{
|
{
|
||||||
flag = true;
|
|
||||||
if (target_left) {
|
if (target_left) {
|
||||||
correct = true;
|
correct = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (e.which == trial.right_key) // 'p' key by default
|
else if (info.key == trial.right_key) // 'p' key by default
|
||||||
{
|
{
|
||||||
flag = true;
|
|
||||||
if (!target_left) {
|
if (!target_left) {
|
||||||
correct = true;
|
correct = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (flag) {
|
|
||||||
var endTime = (new Date()).getTime();
|
|
||||||
var rt = (endTime - startTime);
|
// create object to store data from trial
|
||||||
// create object to store data from trial
|
var trial_data = {
|
||||||
var trial_data = {
|
"trial_type": "xab",
|
||||||
"trial_type": "xab",
|
"trial_index": block.trial_idx,
|
||||||
"trial_index": block.trial_idx,
|
"rt": info.rt,
|
||||||
"rt": rt,
|
"correct": correct,
|
||||||
"correct": correct,
|
"stimulus_x": trial.x_path,
|
||||||
"stimulus_x": trial.x_path,
|
"stimulus_a": trial.a_path,
|
||||||
"stimulus_a": trial.a_path,
|
"stimulus_b": trial.b_path,
|
||||||
"stimulus_b": trial.b_path,
|
"key_press": info.key
|
||||||
"key_press": e.which
|
};
|
||||||
};
|
block.writeData($.extend({}, trial_data, trial.data));
|
||||||
block.writeData($.extend({}, trial_data, trial.data));
|
|
||||||
$(document).unbind('keydown', resp_func); // remove response function from keys
|
display_element.html(''); // remove all
|
||||||
display_element.html(''); // remove all
|
|
||||||
xab_trial_complete = true;
|
xab_trial_complete = true;
|
||||||
// move on to the next trial after timing_post_trial milliseconds
|
|
||||||
if(trial.timing_post_trial > 0) {
|
// move on to the next trial after timing_post_trial milliseconds
|
||||||
setTimeout(function() {
|
if(trial.timing_post_trial > 0) {
|
||||||
block.next();
|
setTimeout(function() {
|
||||||
}, trial.timing_post_trial);
|
|
||||||
} else {
|
|
||||||
block.next();
|
block.next();
|
||||||
}
|
}, trial.timing_post_trial);
|
||||||
|
} else {
|
||||||
|
block.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
$(document).keydown(resp_func);
|
|
||||||
|
jsPsych.getKeyboardResponse(after_response, [trial.left_key, trial.right_key], 'date', false);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user