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,

1 Like

Hi Becca! thank you this works like a charm! do you think that is possible to implement this using mouse press (emulate the response not move the mouse) even online?

Hi There,

This currently wouldn’t work online/with mouse clicks but could easily be adapted to!

For the online part, this currently uses the numpy library for choice and linspace - so would need to implement the JS equivalent of those.

For the mouse click part the framework would be near identical, only with simulating a click rather than a key press.

I have a feeling this would make a nice demo for psychopy but could take a bit more work (so I am bookmarking this thread to revisit in the future). But, in the meantime if you have developments in extending the demo please do share those!