(if "backspace" in keys) Not Working

OS (OS Monterey 12.4):
PsychoPy version (2023.2.1)
Standalone (y)
**My old code for picking up on the ‘backspace’ key and using it to remove the last character from a string doesn’t work anymore. The code is in python and pushed to Pavlovia through the automatic javascript translation. This has always worked, I believe it might be an issue with the new version. Here is a snippet of the code with the relevant part:

if len(keys):
if ‘space’ in keys:
engbox_txt44.text = engbox_txt44.text + ’ ’
elif ‘backspace’ in keys:
engbox_txt44.text = engbox_txt44.text[:-1]
**

When I changed the ‘backspace’ piece to ‘space’ or any other key the code worked fine and the last character was deleted. The issue I imagine is with the code not recognizing the ‘backspace’ key.

No character is actually removed from the string.

I’ve noticed the same problem. Running in version 2023.1.3 seems to fix the issue, but it recurs if setting the experiment to run in any more recent version. I’m guessing that it’s a bug (or other change in keypress handling) that must have been introduced version 2023.2.0.

I’ve been using the following code, that IIRC I adapted from one of Wakefield Morys-Carter’s demos. It’s run well for three years previously, but from 2023.2.0 onwards the backspace function no longer works. 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.

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;
}