| Reference | Downloads | Github

Auto-response script in Psychopy

I would like to know if could be possible to write a script that automatically press a key or a mouse button in order to simulate an experiment and debug in real-life the code.
Could it be possible?


Would something like this work for what you had in mind?

  1. make a class to generate a simulated key press response:

class simKeys:
    an object to simulate key presses
    keyList: a list of keys to watch
    name: randomly selected from keyList
    rtRange: [min RT, max RT] where min and max RT are sepecified in ms
   rt: randomly selected from rtRange
    def __init__(self, keyList, rtRange):
        self.rt = np.random.choice(np.linspace(rtRange[0], rtRange[1])/1000)
  1. at the start of your routine make a simulated key object:
thisSimKey=simKeys(keyList=['left', 'right'], 
  1. When the rt of that simulated keypress is reached add it to your key response object so that the routine is ended
if t >= thisSimKey.rt:

Here is an associated demo file simulate_response.psyexp (14.1 KB)

Hope this helps,