psychopy.org | Reference | Downloads | Github

Auto-response script in Psychopy

Hi,
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?

Hi,

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.name=np.random.choice(keyList)
        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'], 
    rtRange=[200,1000])
  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:
    _key_resp_allKeys.extend([thisSimKey])

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

Hope this helps,
Becca