0

I've been battling this issue for several hours and my attempts to find a solution online have come up blank. Hopefully someone here has some insight.

In the course of an experiment, participants see a series of stimuli followed by masks with no user input. However, on some trials we want to throw in "catch" trials to make sure the participant is still engaged.

So ideally, the flow would look like:

stim->mask->stim->mask...->catch trial->mask (register keypress - "I saw it")->stim->mask...

The problem I'm having is that when I call event.getKeys('space') it invariably returns an empty list.

Here's a snippet of relevant code:

            if stimCount >= min(catchTrials)+mod[modCount] and stimCount <= max(catchTrials)+mod[modCount] and beenDisplayed == 0:
                print 1
                test = random.randint(0,1)
                if test == 1 or stimCount % 20 == 0:
                    print 2
                    actualStim.setSF(0)
                    actualStim.setOri(0)
                    doCatch(catchTimeout) # this displays the "catch" stim
                    doMask(MaskTimeout,maskNum) # this is the mask
                    print stimCount+1, 'catch', catchResponse # debug line
                    beenDisplayed = 1
                    modCount += 1
                    inCatch = 1
                    keys = event.getKeys(["space"]) # should return *something* that was pressed?
                    print 'keys = ',keys
                    if len(keys) > 0: # logic given a keypress
                        print 'pressed'
                        catchResponse[0] = 1
                    else:
                        print 'not pressed'
                        catchResponse[0] = 0

                else:
                    maskNum = str(1) 
                    doFixate(FixateTimeout)
                    actualStim.setSF(Circle1[stimCount][1])
                    actualStim.setOri(Circle1[stimCount][2])
                    #doMask(MaskTimeout,maskNum)
                    print stimCount+1, inCatch
                    if inCatch == 1:
                        print str(keyMap[response["firstKey"]])
                    doStimulus(None, StimTimeout, None)
                    doMask(MaskTimeout,maskNum)

  Output: 
    5 0
    1
    6 0
    1
    2
    7 catch [0, 1]
    keys =  []
    not pressed
    8 0

As I understand it, event.getKeys() returns a list of all keys pressed since the last getKeys was called, or a clearEvent is called.

In this case, I don't understand why keys is always empty. I've tried moving the getKeys event all over the loop and to no avail.

I would greatly appreciate any help, Ben

Ben
  • 29
  • 1
  • 3
  • You don't actually show your loop structure here, so it is hard to know how your code works. event.getKeys() is designed for checking what was pressed at a given instance in time, so it is best suited to being in a reasonably tight loop (e.g. checking on every screen refresh). Otherwise, it is quite possible, for example, to check for a keypress before a reaction time has elapsed. We can't tell from the above when you are checking, and whether keypresses could slip through. If you could strip the extraneous detail out to make a minimal reproducible example, that would also be useful. – Michael MacAskill Jan 15 '15 at 09:22
  • You could also use event.waitKeys() - it is also possible to specify timeout for waitKeys. – mmagnuski Apr 07 '15 at 11:17

0 Answers0