Description of the problem: I cannot delete i.e. use backspace on the entered response in text boxes. Essentially backspace is not being registered. I know people have reported this before but could not find a solution here so I’m sharing this again. I’ve tried editing the code, using an editable text box without the code component and using a keyboard reponse element but nothing is working. This is the code I had before [note: taken from a previous experiment in my lab and was working before]:
Begin experiment : import string
allLetters = list(string.ascii_lowercase+string.digits)
Begin routine : //temporary solution to a psychopy bug
word3_2.refresh();
document.body.style.cursor='auto';
//modify = false;
**Each frame** : let theseKeys = psychoJS.eventManager.getKeys({keyList: ['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','1','2','3','4','5','6','7','8','9','0','backspace','-']});
if (theseKeys.length > 0) {
// Get the last key pressed
let key = theseKeys[theseKeys.length - 1];
if (key === '-') {
key = '-'; // Handle the minus sign
} else if (key === 'backspace') {
// Handle Backspace: Remove the last character
if (word3_2.text.length > 0) { //Check if there are any characters to delete
word3_2.text = word3_2.text.slice(0, -1); // Remove the last character
}
} else if (key.length === 1 && (/[a-z0-9-]/.test(key))) {
// Ensure valid characters (alphanumeric and minus) and only one character.
word3_2.text = word3_2.text + key;
}
}