Pavlovia not recognizing 'backspace' key

I have an experiment where I have people type their name. I want then to be able to delete letters (in case they typed it wrong). Locally, on PsychoPy, my code works. When I try to run it on Pavlovia, it longer does. When I look at the datafile, even though, I pressed ‘backspace’, the key is not in the datafile, which is why I think Pavlovia is not recognizing it.

Here is the javascript code I am using.

if(keyResp.keys != undefined && keyResp.keys.length > last_len) {
    last_len = keyResp.keys.length
    key_list.push(keyResp.keys.pop())
    if(key_list.indexOf("backspace") != -1) {
        if (key_list.length > 0) {
            key_list.pop();
        }
    }
    else
    if(key_list.indexOf("return") != -1) {
        key_list.pop(); 
        if (key_list.length >= 2) {
            continueRoutine = false;
        }
    }
    else 
    if(key_list.indexOf("space") != -1) {
    key_list.pop();
    key_list.push(' ');
}
    while (key_list.length > maxDigits) {
        key_list.pop();
    }
    respDisplay = key_list.join("");
}

Please help :slight_smile:

I’m using ‘N/A’ to represent backspace (and other keys that no longer register in keyboard components online) and shift N/A for ?

Textbox components have come a long way but I needed to disable spell check.

Have a look at my key check online demo to see the available keys.

Here’s my Each Frame code for a narrative test.

if key_all.keys:
        if len(key_all.keys) > nKeys:
            if key_all.keys[-1] == 'space' or key_all.keys[-1] == 'return':
                thisExp.nextEntry()
                thisExp.addData('WordTime',myClock.getTime()-wordTime)
                wordTime = myClock.getTime()
                thisExp.addData('Word',oldText[wordPos:])
                thisExp.addData('BackspaceCount',backspaceCount)
                thisExp.addData('TypingTime',myClock.getTime())
                backspaceCount = 0
                if key_all.keys[-1] == 'return':
                    newText += '\n'
                    wordPos = nCharacters + 2
                    allPos.append(wordPos-1)
                else:
                    newText += ' '
                    wordPos = nCharacters + 1
                    allPos.append(wordPos)
            elif key_all.keys[-1] == 'N/A':
                if upperCase:
                    newText += '?'
                    upperCase = False
                elif nCharacters > 0:
                    newText = newText[:-1]
                    if wordPos >= nCharacters:
                        wordPos = allPos.pop()
            elif key_all.keys[-1] == 'backspace':
                 if nCharacters > 0:
                    newText = newText[:-1]
                    if wordPos >= nCharacters:
                        wordPos = allPos.pop()
            elif key_all.keys[-1] == 'left':
                 if nCharacters > 0:
                    newText = newText[:-1]
                    if wordPos >= nCharacters:
                        wordPos = allPos.pop()
            elif key_all.keys[-1] == 'lshift' or key_all.keys[-1] == 'rshift':
                if upperCase:
                    upperCase = False
                else:
                    upperCase = True
            elif key_all.keys[-1] == 'period':
                if upperCase:
                    newText += '>'
                    upperCase = False
                else:
                    newText += '.'
            elif key_all.keys[-1] == 'comma':
                if upperCase:
                    newText += '<'
                    upperCase = False
                else:
                    newText += ','
            elif key_all.keys[-1] == 'semicolon':
                if upperCase:
                    newText += ':'
                    upperCase = False
                else:
                    newText += ';'
            elif key_all.keys[-1] == 'apostrophe':
                if upperCase:
                    newText += '@'
                    upperCase = False
                else:
                    newText += '\''
            elif key_all.keys[-1] == 'minus':
                if upperCase:
                    newText += '_'
                    upperCase = False
                else:
                    newText += '-'
            elif key_all.keys[-1] == 'grave':
                if upperCase:
                    newText += '|'
                    upperCase = False
                else:
                    newText += '\''
            elif len(key_all.keys[-1]) == 1:
                if upperCase:
                    if key_all.keys[-1] == '1':
                        newText += '!'
                    elif key_all.keys[-1] == '2':
                        newText += '"'
                    elif key_all.keys[-1] == '3':
                        newText += '£'
                    elif key_all.keys[-1] == '4':
                        newText += '$'
                    elif key_all.keys[-1] == '5':
                        newText += '%'
                    elif key_all.keys[-1] == '6':
                        newText += '^'
                    elif key_all.keys[-1] == '7':
                        newText += '&'
                    elif key_all.keys[-1] == '8':
                        newText += '*'
                    elif key_all.keys[-1] == '9':
                        newText += '('
                    elif key_all.keys[-1] == '0':
                        newText += ')'
                    else:
                        newText += key_all.keys[-1].upper()
                    upperCase = False
                else:
                    newText += key_all.keys[-1]
           # nSpaces = len(key_all.keys)
            nKeys += 1

nCharacters = len(newText)
if oldLength > nCharacters:
    backspaceCount += 1
oldLength = nCharacters
if cursorCounter >= 30:
    if cursorVariable=='|':
        cursorVariable=' '
    else:
        cursorVariable='|'
    cursorCounter=0
    oldText = '|'
cursorCounter+=1
if newText != oldText:
    textbox_3.text = newText+cursorVariable
    oldText = newText
if timeStarted == True:
    newClock=600-myClock.getTime()   
    if newClock <= 0:
        continueRoutine = False

Hi @wakecarter ,
Just to clarify, does this all mean that one can no longer use Backspace as a key press response to, for example, end a Routine? Is there a plan to re-implement this functionality or is there an important reason that it is no longer possible? We use this in instruction trials, to make sure our participants know how to correct their typed answers, so it is a shame to lose this option.
And the code you shared above is python, right? Do you have the equivalent for psychoJS by any chance?
Thanks and best wishes,
Donna

I’m using this code to register the backspace. I’ll nudge my bug report to see if there’s any progress on this.

My Python code goes into an Auto->JS code component to make the PsychoJS code.

1 Like