Using keys to move stimulus: quick and slow movement while keeping record of the pressed keys

Yep, but just set clear=False for keysB as well and only set it to true for the final getKeys that catches all of the key-presses.

Basically what you’re looking for is adding a counter for consecutive frames on which ‘s’ or ‘d’ has been detected as pressed, and then modifying the speed of the position marker accordingly. Something like this might work:

    if keysB:
        for k in keysB:
            keyB = keysB[-1].name
            if keyB == 's':
                dcounter = 0 # Resetting the counter for D if it is not pressed
                speed = .01
                scounter += 1
                if scounter >= 40:
                    speed = .2
                elif scounter >= 20:
                    speed = .1
                elif scounter >= 10:
                    speed = .05
                markerStim.pos -= [speed, 0]

And the same for D, and just have it that if keysB is false or is not S, the counter resets to 0.

It might be tricky to do with getKeys because of the buffer-clear issue. The solution offered here might be a reasonable alternative if you have trouble getting it to work with getKeys:

1 Like