Looking for help with inline script executing ACE setup
Hi all,
I'm trying to create an "Action-sentence-compatibility" experiment. This requires the participant to hold down a key while reading a sentence and then releasing the key to press another key to categorize the sentence. This means I need to measure "keyrelease". I found an old thread dealing with this (http://forum.cogsci.nl/index.php?p=/discussion/206/solved-key-realease), so I copied the code in that thread and it works great.
The issue is that I want to add a keypress after the keyrelease code (to capture the 2nd key pressed by the participant to categorize the sentence). I want to do this within the same inline code script (I suspect that will offer better timing reliability).
I've tried a few different things, but my computer keeps freezing, which I assume means my "while loop" is not evaluating properly.
Here's my modified code - any help would be very welcome. It works fine until the 2nd keypress part at the end (if I remove that it works perfectly).
(On a related topic, does anyone know what kind of response-time variability this kind of code will deliver?)
from psychopy import visual, core
from pyglet.window import key
response = key.KeyStateHandler()
self.experiment.window.winHandle.push_handlers(response)
fileChain = r"D:\\Users\\ms16492\\Documents\\OpenSesameScripts\\ACE_Arabic\\"
var.trialCounter = i
pressDuration = 0
win = self.experiment.window
time = core.Clock()
#The sentence to be displayed.
sentence = fileChain + "arab" + str(i) + "cropped.png"
#The prompt before the sentence.
testString = "Hold down the g key, hit the a key if the sentence was meaningful, and the l key if it was meaningless."
#message between trials.
intermediateString = "Get ready for the next trial"
press = visual.TextStim(win, pos=(0,0), color = "black", text=testString + str(i) + " " + str(pressDuration))
release = visual.ImageStim(win, pos=(0,0), image=sentence)
intermediate = visual.TextStim(win, pos=(0,0), color = "black", text=intermediateString)
# key not pressed
while not response[key.G]:
press.draw()
win.flip()
t1 = time.getTime() # key pressed! (first timestamp)
#Make this variable generally accessible:
var.t_1 = t1
core.wait(0.1)
while response[key.G]:
release.draw()
win.flip()
t2 = time.getTime() # key released! (second timestamp)
#Make this variable generally accessible:
var.t_2 = t2
pressDuration = t2-t1 # compute the key pressing time
#Make this variable generally accessible:
var.press_duration = pressDuration
core.wait(0.1)
#TRYING TO COLLECT A SECOND KEYPRESS HERE.
response2 = key.KeyStateHandler()
self.experiment.window.winHandle.push_handlers(response2)
while not response2[key.A]:
intermediate.draw()
win.flip
`
Comments
Hi,
If you just want to get a keypress response, you could use the code below. It uses Opensesame instead of going directly into PsychoPy. I don't think it matters, but make sure that it works how you expect it to. Of course you could do this also with PsychoPy, but I don't know the commands by heart...
Hope this helps.
Eduard