| Reference | Downloads | Github

Backspace displays in string when pressed - how to get rid of?

Hi all, I’m currently programming a digit span experiment however I am running into an issue with one section the typed responses. Everything works fine until the backspace is pressed. When backspace is pressed in a string of numbers it will display as ‘21backspace6’ rather than deleting the previous element in the string. This task is meant to be migrated online via pavlovia
Here is my code:

if len(key_resp_2.keys) > 0: #to prevent list index error
    if key_resp_2.keys[-1] == 'backspace': #allow backspacing
        try: #to avoid list index errors when backspacing
            print('No need to backspace')
    elif key_resp_2.keys[-1] == 'return': #allows return to end routine
        continueRoutine = False

current_resp = ''.join(key_resp_2.keys)

Thank you for your time

Try pop() which removes the final item by default.

Doesn’t seem to work, I took out the:


and replaced it with


and now it just displays backspace whenever it is pressed

How are you displaying the text?

You could also try printing the list to the console to try to work out what’s happening

I am using the a regular text component calling $current_resp. Everything else works fine just the backspace so it must be something wrong with my code? I also reverted my version to 3.1.5 and the code works fine in that version.