title: PsychoPy: Logging User Input Strings
body: <p>I have a PsychoPy routine that is intended to act as a memory object-span test.  In one loop, the software presents an object (a single text character) followed by a user task multiple times.  The software remembers the string of characters, and later asks the user to enter the characters as they were presented.  This sequence (loop of tasks followed by character recall) is itself presented several times in a larger loop.</p>
  
  <p>The characters are chosen randomly.</p>
  
  <p>I would like to record, either in the CSV file which PsychoPy generates, or a log file of some sort, the characters that the user is entering.  How does one do that in the PsychoPy graphical interface system?</p>
  
  <p>The code block used to record the character sequences is:</p>
  
  <p><strong>Begin Routine</strong></p>
  
  <pre><code>givenAnswer = ""
  returnPressed = False
  
  R_memPrompt.setText("Please enter characters in the order they were presented, then hit 'Return':") 
  R_memPrompt.draw()
  win.flip()
  </code></pre>
  
  <p><strong>Each Frame</strong></p>
  
  <p>loopTest = True
  userInput = ""</p>
  
  <pre><code>if returnPressed == False:
      while loopTest == True:
          response = event.waitKeys(keyList=['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', 'return', 'backspace', 'left'])
          if response[0] == 'return':
              loopTest = False
              returnPressed = True
              continueRoutine = False
          elif response[0] == 'backspace':
              userInput = userInput[:-1]
              userInput = userInput.upper()
              R_disp.setText(userInput)
              R_disp.draw()
              win.flip()
          else:
              userInput = userInput + response[0]
              userInput = userInput.upper()
              R_disp.setText(userInput)
              R_disp.draw()
              win.flip()
  </code></pre>
  
  <p><strong>End Routine</strong></p>
  
  <pre><code>givenAnswer = givenAnswer + userInput
  </code></pre>
  
  <p>A later routine has, as its <strong>Begin Routine</strong></p>
  
  <pre><code>if memorySequence == givenAnswer:  # memorySequence is the prior record of memory characters
      #  do some stuff
  else:
      #  do some other stuff
  </code></pre>
  
  <p>Crude (it is a prototype) but the intent of the <strong>Each Frame</strong> section is simply to reflect characters as they are written to the screen, through the R_disp text stimulus, while allowing the user to backspace and not worry about case sensitivity.  The final answer ends up in <strong>givenAnswer</strong>, 
  and is later compared to <strong>memorySequence</strong> which was built up previously.</p>
  
  <p>I would like to dump the contents of those variables, <strong>memorySequence</strong> and <strong>givenAnswer</strong> to the CSV file or some log file so that I do not lose the information.  </p>
  
  <p>Is there a way to do this?</p>