With what code can I use so that the circles (polygons) will be added according to the duration of pressing the space bar on the keyboard until release
Say, one circle will be added every 500 milliseconds.
I saw and used this code as a starting point:
from psychopy.hardware import keyboard
from psychopy import core
kb = keyboard.Keyboard ()
kb.clock.reset () # when you want to start the timer from
keys = kb.getKeys ([‘right’, ‘left’, ‘quit’], waitRelease = True)
if ‘quit’ in keys:
core.quit ()
for key in keys:
print (key.name, key.rt, key.duration)
And I added
if key.duration> 0.5:
print (0)
Just to test the possibility that this code will work, but I get an error:
-------Run Routine "trial"-------
while continueRoutine:
# get current time
t = trialClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=trialClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
kb = keyboard.Keyboard()
during your trial
kb.clock.reset() # when you want to start the timer from
keys = kb.getKeys(['right', 'left', 'quit'], waitRelease=True)
if 'quit' in keys:
core.quit()
for key in keys:
print(key.name, key.rt, key.duration)
if key.duration > 0.5:
print(0)
Pleased to see you have a solution here. As something that might help here is a similar situation where we increase the size of a polygon based on key press duration Rebecca Hirst / OSARI_online · GitLab for you it should be slightly simpler because you can directly change the size parameter rather than specifically changing two vertices (this is a “filling bar”).
Hope this helps and pleased to see you are making progress,
Becca