Created
September 11, 2019 16:44
-
-
Save EoinTravers/a02226a6c8dd410dc89a989e6060304a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from psychopy import visual, event, core | |
win = visual.Window(size=(600, 400), fullscr=False, units='height', | |
color=[1.,1.,1.], colorSpace='rgb', | |
gammaErrorPolicy='ignore') | |
my_text = visual.TextStim(win=win, color='black', | |
pos=[.33, 0], height=.05, wrapWidth=.66, | |
text='') | |
def wait_for_keys(): | |
'''Returns list of keys pressed.''' | |
keys = event.waitKeys() | |
print('> Keys pressed:', keys) | |
return keys | |
def key_feedback_thing(target): | |
target_letters = list(target) | |
## Show instructions | |
my_text.text = 'Type "%s"' % target | |
my_text.draw() | |
win.flip() | |
## Get the keys pressed | |
keys_pressed = [] | |
for i in range(len(target_letters)): | |
keys = wait_for_keys() | |
keys_pressed.append(keys) | |
## See if they match the target | |
success = True | |
print('Target:', target_letters) | |
print('Pressed:', keys_pressed) | |
for target, pressed in zip(target_letters, keys_pressed): | |
if target not in pressed: | |
success = False | |
print('Success?', success) | |
## Show feedback | |
if success: | |
my_text.text = 'Success! Press any key to go on.' | |
else: | |
my_text.text = 'Failure! Press any key to go on.' | |
my_text.draw() | |
win.flip() | |
wait_for_keys() | |
for word in ['this', 'is', 'a', 'test']: | |
key_feedback_thing(word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment