-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypingTrialPsychopy.py
54 lines (54 loc) · 1.87 KB
/
TypingTrialPsychopy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def typing_trial(win,image_path,instructions):
text=""
shifton=0 # allows caps and ?'s etc
instructions = visual.TextStim(win, text=instructions,color="DimGray",units='norm',pos=[0,0.75], wrapWidth = 1.5)
#you do not need the above line if you do not have any text displayed along with the image
image_stim=visual.ImageStim(win, image=image_path, units='norm',pos=[0,0],autoLog=True)
while event.getKeys(keyList=['return'])==[]:
letterlist=event.getKeys(keyList=['q','w','e','r','t','y','u','i','o','p','a','s','d','f',
'g','h','j','k','l','z','x','c','v','b','n','m','lshift','rshift','period','space','apostrophe','comma','1','slash','backspace'])
for l in letterlist:
if shifton:
if l == 'space':
text+=' '
elif l == 'slash':
text+='?'
elif l == '1':
text+='!'
elif len(l) > 1:
pass
elif l !='backspace':
text+=l.upper()
shifton=0
elif shifton == 0:
#if key isn't backspace, add key pressed to the string
if len(l) > 1:
if l == 'space':
text+=' '
elif l == 'period':
text+='.'
elif (l == 'lshift') | (l == 'rshift'):
shifton=1
elif l == 'comma':
text+=','
elif l == 'apostrophe':
text+='\''
elif l == 'backspace':
text=text[:-1]
elif l == 'slash':
text+='/'
else:
pass
elif l == '1':
pass
else: # it would have to be a letter at this point
text+=l
#otherwise, take the last letter off the string
#continually redraw text onscreen until return pressed
response = visual.TextStim(win, text=text+'|',color="black",units = 'norm', pos = [0,-0.75] )
# text=text+'|' adds a pipe after the typed text to signal where typing will start/continue
response.draw()
instructions.draw()
image_stim.draw()
win.flip()
return text #this allows you to assigned the response to a variable outside the function (e.g., to store it)