use getKeyboardResponse

This commit is contained in:
Josh de Leeuw 2014-06-28 21:50:03 -04:00
parent 62e4d3e9c2
commit ac0ce67f16

View File

@ -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,41 +159,41 @@
} }
// 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": rt, "rt": info.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": e.which "key_press": info.key
}; };
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 // move on to the next trial after timing_post_trial milliseconds
if(trial.timing_post_trial > 0) { if(trial.timing_post_trial > 0) {
setTimeout(function() { setTimeout(function() {
@ -205,9 +202,11 @@
} else { } else {
block.next(); block.next();
} }
}
}; };
$(document).keydown(resp_func);
jsPsych.getKeyboardResponse(after_response, [trial.left_key, trial.right_key], 'date', false);
break; break;
} }
}; };