Hi Nicolas,
Hmm, I will try and make the template active again. In my example I had the following routines:
before > start2 > after
before contains: a text element that lasts for one second and says “before text”
start2 contains: a keyboard component and a code snippet
The keyboard component is:
- set to accept ‘y’ and ‘n’ as responses
- NOT force the end of the routine
- Store all keys
The code snippet has the following in each tab:
- begin routine -
window.kb = kb;
- each frame -
let keyEvents = kb.getEvents();
if (keyEvents .length > 0) {
let keydownTimestamp;
let keyupTimestamp;
let i = 0;
for (; i < keyEvents.length; i++) {
if (keyEvents[i].pigletKey === 'space' && keyEvents[i].status === Symbol.for('KEY_DOWN')) {
//console.log('found keydown at event ' + i);
keydownTimestamp = keyEvents[i].timestamp;
break;
}
}
for (; i < keyEvents.length; i++) {
if (keyEvents[i].pigletKey === 'space' && keyEvents[i].status === Symbol.for('KEY_UP')) {
//console.log('found keyup at event ' + i);
keyupTimestamp = keyEvents[i].timestamp;
break;
}
}
if (keydownTimestamp !== undefined && keyupTimestamp !== undefined) {
console.log('duration ' + (keyupTimestamp - keydownTimestamp));
kb.clearEvents();
continueRoutine = false;
}
}
After text contains: a text element that lasts for one second and says “after text”
This seems to only work once deployed in Pavlovia. Please let me know if this helps!