Hi,
Just as a style point, you might find it useful to move to more Pythonic ways of running your loops: these look like they are influenced from previous experience with other programming languages. e.g. instead of:
for x in range(len(audio_stimuli_per_block)):
# other stuff, then:
audio_stimuli_per_block[x].play()
simply do this:
for stimulus in audio_stimuli_per_block:
# other stuff, then:
stimulus.play()
i.e. in Python we can often avoid the need for keeping track of a loop index, and that can simplify the readability of the code.
Now for the actual problem, it is a little bit unclear what “no keypresses are accessible” actually means. But I suspect this is due to your code structure. At the moment you are effectively checking for a keypress only twice per trial, at instantaneous points in time. i.e. event.getKeys()
is an instantaneous check. If no key has been pressed since the start of the trial (when you clear the event queue) or since the last call to event.getKeys()
, then the code will simply continue.
During those core.wait()
periods, no keypresses can be detected in real time. If a key was pressed, it should be found waiting in the queue, but the timing that gets returned to you will be incorrect: the time stamp from event.getKeys()
is the time that you issue the check (i.e. the time that pull the event out of the queue), not the time that the key was actually pressed. So event.getKeys()
really needs to be used in a tight loop, so that presses are detected soon after they occur.
Hard to make recommendations here without more detail of what you actually want to achieve, but anyway, the event
module is now being superseded by a better way of checking the keyboard, which does retrieve the time the key was pressed, even if it occurred quite some time before issuing the command.
See documentation on the new Keyboard
class here: