Textbox does not record a new letter in replace of a deleted one

Hi,

I am using this code that was given to me to record each letter as it is typed within the textbox. However, when a participant types in the textbox, makes a mistake, deletes for example the last letter of the word, they then replace that letter with the correct one, this letter is not recorded.

E.g. Participants inputs ‘CAY’ they then delete ‘Y’ and replace ‘Y’ with a ‘T’, letter column of the data sheet only records the Y and not the T.

I want the programme to record everything, even the letter that was deleted and the letter that it was replaced with. The code that I am currently using is below.

nCharacters = len(Text_Box.text)

if nCharacters > oldLength:
thisExp.nextEntry()
thisExp.addData(‘Letter’,Text_Box.text[-1])
thisExp.addData(‘RT’,myClock.getTime())
oldLength = nCharacters

Thank you for any help!

Try

nCharacters = len(Text_Box.text)

if nCharacters > oldLength:
     thisExp.nextEntry()
     thisExp.addData('Letter',Text_Box.text[-1])
     thisExp.addData('RT',myClock.getTime())
     oldLength = nCharacters
elif nCharacters < oldLength:
     thisExp.nextEntry()
     thisExp.addData('Letter','Backspace')
     thisExp.addData('RT',myClock.getTime())
     oldLength = nCharacters

This works perfectly! Thank you

1 Like