diff --git a/docs/overview/timeline.md b/docs/overview/timeline.md index 095e8773..25ad060c 100644 --- a/docs/overview/timeline.md +++ b/docs/overview/timeline.md @@ -337,7 +337,7 @@ var trial = { var loop_node = { timeline: [trial], loop_function: function(data){ - if(jsPsych.pluginAPI.convertKeyCharacterToKeyCode('r') == data.values()[0].key_press){ + if(data.values()[0].key_press == 'r'){ return true; } else { return false; @@ -367,7 +367,7 @@ var if_node = { // get the data from the previous trial, // and check which key was pressed var data = jsPsych.data.get().last(1).values()[0]; - if(data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode('s')){ + if(data.key_press == 's'){ return false; } else { return true; diff --git a/docs/tutorials/rt-task.md b/docs/tutorials/rt-task.md index df014d6b..05c4dafb 100644 --- a/docs/tutorials/rt-task.md +++ b/docs/tutorials/rt-task.md @@ -863,12 +863,12 @@ var test = { choices: ['f', 'j'], data: jsPsych.timelineVariable('data'), on_finish: function(data){ - data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response); + data.correct = data.key_press == data.correct_response; } } ``` -The `data.key_press` value is a numeric key code indicating which key the subject pressed. The function `jsPsych.pluginAPI.convertKeyCharacterToKeyCode` converts the character representation of a key into the numeric representation (e.g., calling the function on the value `'f'` generates the value `70`). If this numeric value matches `data.key_press` then `data.correct` will be `true`. Otherwise, it will be `false`. +The `data.key_press` value is a string representation of the key the subject pressed. We can compare this with the `data.correct_response` value, and assign this computer value to a new property `data.correct`. ### The complete code so far @@ -936,7 +936,7 @@ The `data.key_press` value is a numeric key code indicating which key the subjec choices: ['f', 'j'], data: jsPsych.timelineVariable('data'), on_finish: function(data){ - data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response); + data.correct = data.key_press == data.correct_response; } } @@ -1064,7 +1064,7 @@ This code is available in the examples folder in the jsPsych download. It is cal choices: ['f', 'j'], data: jsPsych.timelineVariable('data'), on_finish: function(data){ - data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response); + data.correct = data.key_press == data.correct_response; }, } diff --git a/examples/conditional-and-loop-functions.html b/examples/conditional-and-loop-functions.html index 61d6669e..775e81d8 100644 --- a/examples/conditional-and-loop-functions.html +++ b/examples/conditional-and-loop-functions.html @@ -17,7 +17,7 @@ var loop_node = { timeline: [trial], loop_function: function(data){ - if(jsPsych.pluginAPI.convertKeyCharacterToKeyCode('r') == data.values()[0].key_press){ + if(data.values()[0].key_press == 'r'){ return true; } else { return false; @@ -40,7 +40,7 @@ timeline: [if_trial], conditional_function: function(){ var data = jsPsych.data.get().last(1).values()[0]; - if(data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode('s')){ + if(data.key_press == 's'){ return false; } else { return true; diff --git a/examples/demo-simple-rt-task.html b/examples/demo-simple-rt-task.html index 7584e044..a3646e2d 100644 --- a/examples/demo-simple-rt-task.html +++ b/examples/demo-simple-rt-task.html @@ -62,7 +62,7 @@ choices: ['f', 'j'], data: jsPsych.timelineVariable('data'), on_finish: function(data){ - data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response); + data.correct = data.key_press == data.correct_response; }, } diff --git a/examples/lexical-decision.html b/examples/lexical-decision.html index 91ccdf15..a43abd74 100644 --- a/examples/lexical-decision.html +++ b/examples/lexical-decision.html @@ -88,9 +88,9 @@ }, on_finish: function(data){ if(data.word_validity == 'valid'){ - var correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode('y'); + var correct = data.key_press == 'y'; } else { - var correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode('n'); + var correct = data.key_press == 'n'; } data.correct = correct; } diff --git a/plugins/jspsych-reconstruction.js b/plugins/jspsych-reconstruction.js index 28dc90db..5af4f20d 100644 --- a/plugins/jspsych-reconstruction.js +++ b/plugins/jspsych-reconstruction.js @@ -67,8 +67,8 @@ jsPsych.plugins['reconstruction'] = (function() { //console.log('fire'); - var key_i = (typeof trial.key_increase == 'string') ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.key_increase) : trial.key_increase; - var key_d = (typeof trial.key_decrease == 'string') ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.key_decrease) : trial.key_decrease; + var key_i = trial.key_increase; + var key_d = trial.key_decrease; // get new param value if (info.key == key_i) { diff --git a/plugins/jspsych-same-different-html.js b/plugins/jspsych-same-different-html.js index be428c38..27f56e6c 100644 --- a/plugins/jspsych-same-different-html.js +++ b/plugins/jspsych-same-different-html.js @@ -124,8 +124,8 @@ jsPsych.plugins['same-different-html'] = (function() { var correct = false; - var skey = typeof trial.same_key == 'string' ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.same_key) : trial.same_key; - var dkey = typeof trial.different_key == 'string' ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.different_key) : trial.different_key; + var skey = trial.same_key; + var dkey = trial.different_key; if (info.key == skey && trial.answer == 'same') { correct = true; diff --git a/plugins/jspsych-same-different-image.js b/plugins/jspsych-same-different-image.js index f540af7e..382fc10c 100644 --- a/plugins/jspsych-same-different-image.js +++ b/plugins/jspsych-same-different-image.js @@ -125,8 +125,8 @@ jsPsych.plugins['same-different-image'] = (function() { var correct = false; - var skey = typeof trial.same_key == 'string' ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.same_key) : trial.same_key; - var dkey = typeof trial.different_key == 'string' ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.different_key) : trial.different_key; + var skey = trial.same_key; + var dkey = trial.different_key; if (info.key == skey && trial.answer == 'same') { correct = true;