jspsych / jsPsych

Create behavioral experiments in a browser using JavaScript
http://www.jspsych.org
MIT License
1.02k stars 655 forks source link

Experiment-wide keyboard tracking extension (& further keypress tracking) #2868

Open nikbpetrov opened 1 year ago

nikbpetrov commented 1 year ago

Experiment-wide keyboard tracking extension

Similar to the mouse-tracking extension, it could be useful to have a keyboard-tracking one as well. I imagine both of these, unlike the current version of the mouse-tracking one, to be experiment-wide, similar to the interaction data.

More detailed keypress tracking

It could also be useful, in this sort of plugin, to also have tracking of the type of keypress that was done as well as whether it was part of a held key or not (see below for more). This could be a separate issue and expand existing keyboard plugins as needed.

Possible implementation

Here's my, rather rudimentary at this stage, implementation:

keystrokes_tracking_demo2

I can't share my code as it's work in progress and it's complete trash (albeit rather working), but here are a few considerations:

jodeleeuw commented 1 year ago

This sounds like a great addition 🥳

I'm not sure I'm following the point about the interaction data. Typically extensions will write data into trials that have the extension enabled. Are you imagining a different flow for this extension?

I think it would be great to test run this in jspsych-contrib and then we can move it over to the main repo once it feels like a stable feature set.

nikbpetrov commented 1 year ago

I don't think I will have the time to write it up properly for the contrib library as I am working on developing an experiment-wide 'extension' as opposed to the current trial-specific setup that jsPsych has.

Specifically, as you point out, jsPsych currently implements extensions on a trial-by-trial basis. What I need for this is an experiment-wide tracking of ALL keyboard presses. To achieve this, I've implemented the keyboard listener within the interaction data-related stuff so that keyboard presses are treated in the same way as other window interaction events.