Open nikbpetrov opened 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.
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.
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:
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:
getKeyboardResponse
is quite solid already, so perhaps just use that and allow custom options (e.g. I might want to track held keys)event.repeat
method allows distinguishing between held keys and key presses, see here; it's quite useful to add that to the datagetKeyboardResponse
registered in thecreateInteractionListeners
method of theJsPsychData
class)getKeyboardResponse
method registers on the "root", which might not be the desired behaviour if this is used for experiment-wide tracking; however, it's complex if you consider 1) experiments done as part of iframes and 2) interaction between the tracking and the browser (e.g. clicking F5, currently in my version, does not refresh the page)