Why is my event.getKeys() memory buffer not clearing?

Hey everyone, I appreciate the assistance.

@Becca, I really appreciate you taking the time to make that in the builder. It looks great. Unfortunately, for our purposes, though, I cannot use the builder scale, as it demands mouse access and we’re going to have people completing this task while undergoing an MRI, so no mouse access, and we need their ratings on a second-by-second scale for over an hour.

@mmagnuski I appreciate you preparing that. It looks like it could certainly work. For our purposes, participants will only have access to two buttons, so relying on a third to make the scale stop isn’t possible, which is why I have to source event.getKeys twice with release= True, clear = True.

Prior to seeing either of these comments, I came up with my own solution. Sorry I hadn’t seen them earlier. I simply altered the conditional logic to specify that keys can only take a directional value if only one of the keys is currently being pressed. The issue always seems to generate when changing directions, so by limiting one’s ability to do that quickly, I seem to have eliminated the problem. For additional insurance, I specified that keys cannot take a directional value if the scale is currently at either pole. I’ve been trying to break the script for a few hours now and haven’t had luck. Of course, I won’t know for sure until it reoccurs, but fingers crossed. Thanks so much again both of you for your time. I really appreciate it.

        if kb.status == STARTED:
           
            # At the start of the loop, we check whether the scale is at either of its poles, 
            # and if so, we reset the keys variable and clear the event log.
            if abs(y1) >= 0.5:
                keys = 'STOP'
                kb.clearEvents()

            # If the left button is being pressed, and the right button is not being 
            # pressed, and the scale is not currently at the left pole, change the 
            # value of keys to LEFT. These additional conditionals are crucial for me.
            if len(kb.getKeys([keyLeft], waitRelease = False, clear = False)) == 1 and len(kb.getKeys([keyRight], waitRelease = False, clear = False)) != 1 and y1 > -0.5:
                keys = 'LEFT'

                # Once the key is released, clear the memory buffer and change 
                # the value of keys to STOP
                if len(kb.getKeys([keyLeft], waitRelease = True, clear = False)) > 0:
                     keys = 'STOP'
                     kb.clearEvents()

            # Just as above, except for the right key. 
            elif len(kb.getKeys([keyRight], waitRelease = False, clear = False)) == 1 and len(kb.getKeys([keyLeft], waitRelease = False, clear = False)) != 1 and y1 < 0.5 :
                keys = 'RIGHT'
                if len(kb.getKeys([keyRight], waitRelease = True, clear = False)) > 0:
                        keys = 'STOP'
                        kb.clearEvents()
1 Like