# Key release as an answer- how to codify different timings

**URL:** <https://discourse.psychopy.org/t/key-release-as-an-answer-how-to-codify-different-timings/4524>\
**Category:** Coding\
**Created:** [May 16, 2018, 12:20pm UTC](https://discourse.psychopy.org/t/key-release-as-an-answer-how-to-codify-different-timings/4524 "2018-05-16T12:20:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartaCasales](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@MartaCasales](https://discourse.psychopy.org/u/MartaCasales)\
**Post date:** [May 16, 2018, 12:20pm UTC](https://discourse.psychopy.org/t/key-release-as-an-answer-how-to-codify-different-timings/4524/1 "2018-05-16T12:20:55Z")

</div>

Hi all,

I am trying to create an imitation-inhibition task in which the responses to the experimental conditions (congruent and incongruent stimuli)are done by releasing the pressed keys. The keys are “v” and “b”, and they have to response to a finger lifting image. I also have a control condition in which the hand appears static for 5 seconds. For the key release I have iohub codes.  
The problem is that, for the control conditions, it needs a reply to go to the next image, but I don’t want participants to give a reply, I want the image to stay for 5 seconds and go away while they keep those keys pressed. How can I specify that the control condition does not need an answer?

I have this codes for the key release:

In the first routine of instructions (before any loop):  
Begin experiment:  
try:  
from psychopy.iohub import EventConstants,KeyboardConstants,ioHubConnection,load,Loader  
from psychopy.data import getDateStr  
# Load the iohub device config, file converting it to a python dict.  
io\_config=load(file(‘iohub\_config.yaml’,‘r’), Loader=Loader)

```
# Add / Update the session code to be unique. Here we use the psychopy getDateStr() function for session code generation
session_info=io_config.get('data_store').get('session_info')
session_info.update(code="S_%s"%(getDateStr()))

# Create an ioHubConnection instance, which starts the ioHubProcess, and informs it of the requested devices and their configurations.
io=ioHubConnection(io_config)
iokeyboard=io.devices.keyboard
iomouse=io.devices.mouse

```

except Exception, e:  
import sys  
print “!! Error starting ioHub: “,e,” Exiting…”  
sys.exit(1)

trialn = 0  
trial\_start=0

End experiment: io.quit()

In the practice trial (the first loop), we have this code:  
Begin experiment:  
Countcorr = 0 #to reset the counter for corrrect responses to 0

Begin routine:

# START get\_vb\_keys Begin Routine

vb\_keys\_released=False

# END get\_vb\_keys Begin Routine

Each frame:  
response\_events = iokeyboard.getReleases(keys=[‘v’,‘b’])  
if response\_events:  
response\_event = response\_events[0]  
vb\_keys\_released=False

End routine:  
if response\_event is None:  
response\_events = iokeyboard.waitForReleases(maxWait=1000.0, keys=[‘v’,‘b’])  
response\_event = response\_events[0]

trials.addData(“resp.time”, response\_event.time)  
trials.addData(“resp.rt”, response\_event.time-trial\_start)  
trials.addData(‘resp.keys’,response\_event.key)  
trials.addData(‘resp.corr’, response\_event.key==corrAns)

#check for consecutive correct responses  
if response\_event.key==corrAns: #if the keys are pressed for the correct answer  
Countcorr = Countcorr + 1 #then variable updates by adding 1 to the counter  
else:  
Countcorr = 0 #if an incorrect response is made, then reset counter

print Countcorr

if Countcorr == 10:  
trials.finished = True #finish the practice block after 10 consecutive correct responses

io.clearEvents()  
iokeyboard.clearEvents()  
response\_event = None  
vb\_keys\_released=False

# FINISHED get\_vb\_release end routine

I am not sure if that is everything needed to explain my doubt.  
Thanks for the information!
