我试图让用户能够通过按向上或向下键来调整在psychopy中显示的行的长度。我正在使用 event.getKeys(),但是,它没有记录按下的键。我不知道为什么,但它总是显示一个空的键列表。这是我的代码:
class line(object):
def makeLine(self,length):
line = visual.Line(win=win,ori=-45,lineRGB=[-1,-1,-1],lineWidth=3.0, fillRGB=None,
pos= [0,0],interpolate=True,opacity=1.0,units='cm',size=length)
#describes the line
return line.draw()
line2length=2#original length of the line
line2=line()#makes line2 an instance of line class
line2.makeLine(line2length)#calls the makeLine function of the line class
win.flip()#updates the window
keys = event.getKeys()
expInfo['KeyPress']=keys
event.waitKeys(['return'])
print keys
for key in keys:
if 'up' in key:
line2length+=.5
line2.makeLine(line2length)
win.flip()
if 'down' in keys:
line2length-=.5
line2.makeLine(line2length)
win.flip()
event.clearEvents()
thisExp.nextEntry()