Getting text input from participants but the code need improvements

Hi all!

I had been trying to tackle with the problem of getting responses from participants but luckily I came across with a piece of code that made it possible for participants to enter responses without using guidlg. However there are two issues that, I feel, will surely effect the response times:

-When pressed “backspace” key, it only removes the last character. Holding backspace key does not act like what it generally does in word processors.

-Since the responses are usually 1-2 sentences long, any typo/word they want to correct/change/delete can only be done by deleting the characters one by one until they reach the target word/character. In other words, arrow keys or mouse cannot be used to target specific location within the text.

The code is as follows

Begin Experiment
----------------

inputText = ""

Begin Routine
----------------

theseKeys=""
shift_flag = False
text_3.alignHoriz ='left'

Each Frame
----------------
n= len(theseKeys)
i = 0
while i < n:

    if theseKeys[i] == 'return':
        # pressing RETURN means time to stop
        continueRoutine = False
        break

    elif theseKeys[i] == 'backspace':
        inputText = inputText[:-1]  # lose the final character
        i = i + 1

    elif theseKeys[i] == 'space':
        inputText += ' '
        i = i + 1

    elif theseKeys[i] in ['lshift', 'rshift']:
        shift_flag = True
        i = i + 1
    elif theseKeys[i] == 'period':
        inputText = inputText + "."
        i = i + 1
    elif theseKeys[i] == 'comma':
        inputText = inputText + ","
        i = i + 1

    else:
        if len(theseKeys[i]) == 1:
            # we only have 1 char so should be a normal key, 
            # otherwise it might be 'ctrl' or similar so ignore it
            if shift_flag:
                inputText += unichr( ord(theseKeys[i]) - ord(' '))
                shift_flag = False
            else:
                inputText += theseKeys[i]

        i = i + 1

End Routine
----------------

# let's store the final text string into the results finle...
thisExp.addData('inputText', inputText)
inputText=""

Since I am fairly new to python coding I am hopelessly trying adding functions/additions that I find on the web to the current code but havent been successful at making the change I need. For the last 3 hours I have been trying to understand the code in https://pythonhosted.org/pyglet/programming_guide/text_input.py There might be solution offered within this file as there are specific functions like “on_mouse_press” and “on_mouse_drag” however I cant implement it with my current programming knowledge. I would be really glad if you guys can point me in the right direction!

Hello, I’m having similar issues with participants having to delete everything following the text error. I know this is from many years ago and no help on the forum was given but I was wondering if you ever found a solution to this issue and would be willing to share.

You might be interested in word_association [PsychoPy] which includes a free recall task allowing both arrow keys and (to a lesser extent) mouse interaction.