I’m collecting timed typed responses for an online experiment using the following code, which IIRC I adapted from one of Wakefield Morys-Carter’s demos. It is intended to get keys from keyboard presses, save RTs for each keystroke, and display the resulting string on the screen. So if someone presses ‘c’ ‘o’ ‘t’, they’d see ‘cot’, but if they pressed ‘c’ ‘o’ ‘a’ ‘t’, they’d see ‘cat’ instead. The code has run well for three years previously, but since updating PsychoPy I’ve noticed that the backspace/delete function no longer works: ‘c’ ‘o’ ‘a’ ‘t’ produces ‘coat’ instead of ‘cat’.
If I set the experiment to run in Psychopy 2023.1.3, it works fine, but from 2023.2.0 onwards the backspace function no longer works.
Another user noted a similar problem in Sept for an experiment that translated code from JS to Python ((if "backspace" in keys) Not Working). IDK if it’s relevant, but I’m using a Mac (where the ‘backspace’ key is labeled as ‘delete’ and thus might have a technically different mapping from PC backspace keys), so maybe it could be a problem with how the PsychoJS now handles Mac keyboards.
Is there a change with how psychoJS.eventManager.getKeys handles the backspace or delete keys?
let theseKeys = psychoJS.eventManager.getKeys({keyList:['return','space','backspace','lshift', 'rshift','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']});
if (theseKeys.length > 0) { // at least one key was pressed
textAdd = theseKeys[theseKeys.length-1];
}
if (textAdd === 'return') {
textAdd = ''; // Add nothing
if (text.text.length > 0) {
continueRoutine = false; // End routine (if that is what you want)
}
} else if (textAdd === 'space') {
if (text.text.length > 0) {
textAdd = ' '; // Add a space
} else {
textAdd = ''; // Add nothing
}
} else if (textAdd === 'backspace') {
text.text = text.text.slice(0, -1);
textAdd = undefined;
} else if (['lshift', 'rshift'].includes(textAdd)) {
modify = true;
} else if (textAdd !== undefined) {
if (modify) {
text.text = text.text + textAdd.toUpperCase();
modify = false;
} else {
text.text = text.text + textAdd
}
textAdd = undefined;
}