In an excel spreadsheet, I’m attempting to use numbers 1-9 as corrAns values. When I run the experiment, it does not register these key presses as a response. If I replace the numbers with letters, I don’t run into this problem. My list is simple and not unlike that of the list used in the Stroop demo–the only difference being that I used numbers in place directional arrows.
I left allowed keys blank and force end routine unchecked (I’m using a code component to end routine after correct response has been made). Perhaps it has something to do with the component itself?:
#. In each frame:
If len(key_resp_41.keys) > 0:
If key_resp_41.keys[len(key_resp_41.keys)-1] == keyPress:
continueRoutine = False
This works fine when applied to alphabetical characters.
Excel saves the digits as numerical values, but PsychoPy stores key responses as strings. So you either have to save the keyPress values in Excel as strings (by adding an apostrophe before each digit in Excel, e.g., '1), or you need to convert the keyPress values to strings in Python before doing the comparison:
if key_resp_41.keys:
if key_resp_41.keys[-1] == str(keyPress):
continueRoutine = False
Please note that:
the if keyword should be written in lower-case letters
you can check if the key list is empty by simply doing if key_resp_41.keys:
you can access the latest key press via key_resp_41.keys[-1], which is much simpler than key_resp_41.keys[len(key_resp_41.keys)-1] (btw, why do you want the last and not the first key press?)
the continueRoutine = False block shoul have increased indentation under the 2nd if statement.
Thanks guys! Adding the apostrophes was all it took. I had a feeling it was something like that, but because I’m not really familiar with coding, I wasn’t sure how to make the program recognize each integer as a key press rather than some extraneous value.