Ask Your Question
3

How can I use jsPsych to capture more than one keyboard input during a response task?

asked 2021-11-15 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-25 19:00:00 +0000

nofretete gravatar image

To capture more than one keyboard input during a response task in jsPsych, you can use the on_finish parameter within the trial definition to obtain the response data.

Here's an example code snippet that shows how to capture more than one keyboard input during a response task using jsPsych:

var trial = {
  type: 'html-keyboard-response',
  stimulus: 'Press "a" and "b" at the same time',
  choices: jsPsych.NO_KEYS,
  trial_duration: 5000,
  on_start: function(){
    var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({
      callback_function: end_trial,
      valid_responses: ['a', 'b'],
      rt_method: 'performance',
      persist: true,
      allow_held_key: true
    });
  },
  on_finish: function(data){
    var key_presses = keyboardListener.getHeldKeys();
    data.key_presses = key_presses;
  }
};

function end_trial(){
  jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
  jsPsych.finishTrial();
}

In this example, jsPsych.NO_KEYS is used as the choices parameter to prevent the initial keyboard press from being registered. The on_start function creates a keyboardListener variable that listens for the a and b keys to be held down simultaneously. The on_finish function then obtains the held keys using the getHeldKeys function of the keyboardListener object and stores the data in the key_presses property of the trial data object.

Note that the allow_held_key parameter is set to true in the getKeyboardResponse call, which allows multiple key presses to be recorded simultaneously.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-11-15 11:00:00 +0000

Seen: 2 times

Last updated: Feb 25 '22