当前位置: 首页>>代码示例>>Python>>正文


Python event.waitKeys函数代码示例

本文整理汇总了Python中psychopy.event.waitKeys函数的典型用法代码示例。如果您正苦于以下问题:Python waitKeys函数的具体用法?Python waitKeys怎么用?Python waitKeys使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了waitKeys函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RunProbes

def RunProbes():
    # reset clock
    trialClock.reset()
    # set up stimuli
    message1.setText(probe1_string)
    message2.setText("1) %s\n2) %s\n3) %s\n4) %s\n5) %s" % probe1_options)
    message1.draw()
    message2.draw()
    win.logOnFlip(level=logging.EXP, msg='Probe 1')
    win.flip()
    
    # get response
    key1 = event.waitKeys(keyList=['1','2','3','4','5','q','Escape'],timeStamped=trialClock)
    
    # reset clock
    trialClock.reset()
    # set up stimuli
    message1.setText(probe2_string)
    message2.setText("1) %s\n2) %s\n3) %s\n4) %s\n5) %s" % probe2_options)
    message1.draw()
    message2.draw()
    win.logOnFlip(level=logging.EXP, msg='Probe 2')
    win.flip()
    
    # get response
    key2 = event.waitKeys(keyList=['1','2','3','4','5','q','Escape'],timeStamped=trialClock)
    
    # return results
    return (key1[0],key2[0])
开发者ID:djangraw,项目名称:PsychoPyParadigms,代码行数:29,代码来源:FourLetterTask.py

示例2: display_message

def display_message(win, fix, txt, msg):
    """A function to display text to the experiment window.

    win: psychopy.visual.Window
        The window to write the message to.

    fix: psychopy.visual.Circle
        The fixation point to be removed from the screen.

    txt: psychopy.visual.TextStim
        The text object to present to the screen.
    
    msg: String
        The contents for the text object.

    """
    
    txt.setText(msg)
    fix.setAutoDraw(False)
    txt.setAutoDraw(True)
    win.flip()
    
    event.waitKeys()
    
    txt.setAutoDraw(False)
    fix.setAutoDraw(True)
    win.flip()
开发者ID:Chippers255,项目名称:change_detection,代码行数:27,代码来源:change_detection.py

示例3: showpix

def showpix(stimpath, stim, duration):
    fixation()
    pix = visual.ImageStim(win =win, 
            image = stimpath + stim, 
            pos = [0,0], 
            size = [800, 450], 
            opacity = 1,
            units = 'pix'
            )

    pix.draw()    
  #  win.logOnFlip('parallel port trigger picture: %d' %trigger_stim , level=logging.EXP)
    win.flip()
    stimOnset= trialClock.getTime()
    pparallel.setData(0) # sets all pin lo
    pparallel.setData(trigger_stim) # sets all pin lo
    core.wait(0.005)
    pparallel.setData(0)
    core.wait(duration)
    #mouse.getPressed()
    fixation()
    # get key press at the end of clip
    event.waitKeys(keyList=keyStop)
    respTime= trialClock.getTime()
   

    trials.addData('stimOnset', stimOnset)
    trials.addData('respTime',respTime)  
开发者ID:claire-braboszcz,项目名称:Visemi,代码行数:28,代码来源:visemi.py

示例4: instrDraw

def instrDraw(path):
    jpgList = os.listdir(path)
    for JPG in jpgList:
        ins = visual.ImageStim(win, image=path + JPG)
        ins.draw()
        win.flip()
        event.waitKeys()
开发者ID:anieuwenhuys,项目名称:Blockboard,代码行数:7,代码来源:blockBoard.py

示例5: display_instructions

def display_instructions():
    set_msg('INTRODUCTION','TITLE')
    set_msg('AXB control','MAIN')
    set_msg('Press any key to continue','KEY')
    win.flip()
    core.wait(0.5)
    event.waitKeys()
开发者ID:vincentadam87,项目名称:pitch_experiment,代码行数:7,代码来源:run_experimentAXB.py

示例6: pause

 def pause(self):
     """
     Pause block
     """
     event.clearEvents()
     self.win.flip()
     event.waitKeys()
开发者ID:jbonaiuto,项目名称:infant_eeg,代码行数:7,代码来源:facial_movement_exp.py

示例7: _present_choices

 def _present_choices(self, oleft, oright, trial):
     """Present the left and the right outcomes, first at the left
     and second at the right of fixation. After choice_screen_dur
     fixation cross is colored red for choice_screen_dur2, user has 
     to respond while the cross is red. If user respond before or after
     then show the slow-down or too-slow message, otherwise color the
     outcome pressed yellow for remaining duration. Store all the
     events in dictionary trial, which is an argument to the method.
     Return value is the key pressed."""
     trial['success'] = False # set to True if user responded on time.
     start_time = time.time()
     dist = NUMBER_FIXATION_DIST
     left_outcome = visual.TextStim(self.win, 
                                    text=u"\u20AC" + str(oleft) ,
                                    pos=(-dist, 0))
     right_outcome = visual.TextStim(self.win, 
                                     text=u"\u20AC" + str(oright),
                                     pos=(dist, 0))
     self._render(left_outcome, right_outcome, self.fixation)
     # wait for choice_screen_dur and check if user presses left or right key
     try:
         key = event.waitKeys(maxWait=CHOICE_SCREEN_DUR,
                              keyList=[LEFT_KEY, RIGHT_KEY, ESC_KEY])[0]
     except:
         key = "none"
     #usr responded too early show her slow down message and return
     if key in [LEFT_KEY, RIGHT_KEY]:
         trial['slow_down_msg_event'] = time.time()
         trial['too_fast'] = True
         self._render(slow_down_msg, duration=SLOW_DOWN_MSG_DUR)
         return key
     if key == ESC_KEY:
         self.win.close()
         core.quit()
     # turn the fixation cross red and wait for 1 sec for a user to respond
     trial['fixation_color_red_event'] = time.time()
     self.fixation.color = "red"
     self._render(left_outcome, right_outcome, self.fixation)
     try:
         key = event.waitKeys(maxWait=CHOICE_SCREEN_DUR2,
                              keyList=[LEFT_KEY, RIGHT_KEY])[0]
         trial['key_pressed_event'] = time.time()
     except:
         key = "none"
     self.fixation.color = "black"
     # user did not responded, show too slow msg and return.
     if key == "none":
         trial['too_slow'] = True
         trial['too_slow_msg_event'] = time.time()
         self._render(too_slow_msg, duration=TOO_SLOW_MSG_DUR)
         return key
     #show the pressed key in yellow for the remaining time.
     if key == LEFT_KEY:
         left_outcome.color = "yellow"
     elif key == RIGHT_KEY:
         right_outcome.color = "yellow"
     self._render(left_outcome, right_outcome, self.fixation)
     time_elasped = time.time() - start_time
     core.wait(CHOICE_SCREEN_DUR + CHOICE_SCREEN_DUR2 - time_elasped)
     return key
开发者ID:tima04,项目名称:multimodal-risk,代码行数:60,代码来源:choice_task.py

示例8: _show_instructions

    def _show_instructions(self):
        instructions = self.version['instructions']

        for page in instructions['pages']:
            self.stim['text'].setText(instructions['text'][page])
            self.stim['text'].draw()

            if page == 2:
                self.pics_left['donkey.bmp'].setOri(180.0)
                self.pics_left['donkey.bmp'].draw()
                self.pics_right['donkey.bmp'].draw()
                advance_keys = ['j',]

            elif page == 3:
                self.pics_right['piano.bmp'].setOri(180.0)
                self.pics_right['piano.bmp'].draw()
                self.pics_left['piano.bmp'].draw()
                advance_keys = ['f',]

            elif page == 4:
                self.mask_left.draw()
                self.mask_right.draw()
                advance_keys = ['space',]

            else:
                advance_keys = ['space',]

            self.win.flip()
            event.waitKeys(keyList = advance_keys)
开发者ID:lupyanlab,项目名称:orientation-discrimination,代码行数:29,代码来源:temporal.py

示例9: _show_instructions

    def _show_instructions(self):
        instructions = self.version["instructions"]

        for page in instructions["pages"]:
            self.stim["text"].setText(instructions["text"][page])
            self.stim["text"].draw()

            if page == 2:
                self.pics_left["donkey.bmp"].setOri(180.0)
                self.pics_left["donkey.bmp"].draw()
                self.pics_right["donkey.bmp"].draw()
                advance_keys = ["j"]

            elif page == 3:
                self.pics_right["piano.bmp"].setOri(180.0)
                self.pics_right["piano.bmp"].draw()
                self.pics_left["piano.bmp"].draw()
                advance_keys = ["f"]

            elif page == 4:
                self.mask_left.draw()
                self.mask_right.draw()
                advance_keys = ["space"]

            else:
                advance_keys = ["space"]

            self.win.flip()
            event.waitKeys(keyList=advance_keys)
开发者ID:lupyanlab,项目名称:orientation-discrimination,代码行数:29,代码来源:modality.py

示例10: run_main_experiment

def run_main_experiment():
    time_start = core.getTime()
    time_play = time_start
    order = Exp.make_random_stim_order()
    Nonethird = np.floor(len(order)/3)
    Ntwothird = np.floor(2*len(order)/3)

    t = 0
    for i in order:
        t = t+1
        print(core.getTime() -time_start)
        if t in [Nonethird,Ntwothird]:
            set_msg('Short Break!','MAIN')
            set_msg('Press return to continue','KEY')
            win.flip()
            event.waitKeys(keyList=['return','space'])
            core.wait(1) 



        s = sound_build.make_noisy_stim(i,Exp)
        scaled = np.int16(s/np.max(np.abs(s)) * 32767)
        write('test.wav', 44100, scaled)
        core.wait(time_play - core.getTime())        
        set_msg('Up or down?','MAIN')
        win.flip()        
        playsound(s,vol)
        core.wait(0.1) 
        #core.wait(0.5) #wait 500ms; but use a loop of x frames for more accurate timing in fullscreen
        thisResp = get_response()
        iscorrect = Exp.isRespCorrect(i,thisResp) # 1=correct, O=incorrect, -1=missed
        time_play =  core.getTime() + iti
        dataFile.write('%i,%i,%i\n' %(i, thisResp,iscorrect))
    dataFile.close()
开发者ID:vincentadam87,项目名称:pitch_experiment,代码行数:34,代码来源:run_experiment.py

示例11: ShowPicInstruction

def ShowPicInstruction( txt, duration, picFile, location, col=(0.0, 0.0, 0.0) ):

    instr = visual.TextStim( win, text=txt, pos=(0,-50), color=col, colorSpace='rgb', height=50 )

    pic = visual.ImageStim( win );
    pic.setImage( picFile );

    h = pic.size

    picpos = ( 0, h[1]/2 + 20 )
    textpos = ( 0, -1* instr.height/2 - 10)

    pic.setPos( picpos );
    pic.draw( win );

    instr.setPos( textpos )
    instr.draw(win)


    win.flip()
    if duration < 0:
        event.waitKeys()
    else:
        core.wait( duration )

    win.flip() #clear screen
开发者ID:bwrc,项目名称:WishGLD,代码行数:26,代码来源:WCST_faces_tasktypes_matchingstim.py

示例12: main

def main():
    data = {'start_time': timestamp()}
    data['play'] = True
    try:
        data['id'] = dialog_box()[0]
    except:
        return None
    win = visual.Window([800, 600], allowGUI=True, units='deg',
                        color = "grey",fullscr=FULLSCREEN, monitor="testMonitor")
    dominant_stimulie = get_dominant_stimulie(data['id'])
    choices = random_choices4play(data['id'], NPLAY)
    blocks =  [Visual(win, dominant_stimulie[0], choices["Visual"]),
               Auditory(win, dominant_stimulie[1], choices["Auditory"]), 
               Semantic(win, dominant_stimulie[1], choices["Semantic"])]
    data['choices'] = choices
    data['total_win'] = 0
    for block in blocks:
        corrects = block.play()
        for i in range(0, len(corrects)):
            if corrects[i]:
                data['total_win'] += choices[str(block)][i]['amount']
            data['choices'][str(block)][i]['correctp'] = corrects[i]
    data['finish_time'] = timestamp()
    save_data(data)
    txt = u"You win 10 percent of \u20AC %s."%data['total_win']
    visual.TextStim(win, text=txt, pos=(0,0)).draw()
    win.flip()
    event.waitKeys()
开发者ID:tima04,项目名称:multimodal-risk,代码行数:28,代码来源:play.py

示例13: playclip

def playclip(stimpath, stim):
    fixation()
    core.wait(0.3)
    #pparallel.setData(0) # sets all pin lo
    
    clip = visual.MovieStim(win=win,
            name= 'clip', 
            filename= stimpath + stim,
            size = [800, 450],
            ori =0, 
            pos=[0,0], 
            opacity =1, 
            depth = -1.0
            )
    pparallel.setData(trigger_stim) # sets all pin lo
    core.wait(0.005)
    pparallel.setData(0)
    stimOnset= trialClock.getTime()
    while clip.status != visual.FINISHED:
        clip.draw()
        win.flip()
        
    fixation()
    # get key press at the end of clip
    event.waitKeys(keyList=keyStop)
    respTime= trialClock.getTime()
    #mouse.clickReset()
    #button, time = mouse.getPressed(getTime=True)
    #print('mouse: ', button)
    
    #event.waitKeys(keyList= button)
    trials.addData('stimOnset', stimOnset)
    trials.addData('respTime',respTime)  
开发者ID:claire-braboszcz,项目名称:Visemi,代码行数:33,代码来源:visemi.py

示例14: RunProbes

def RunProbes():
    # reset clock
    trialClock.reset()
    # set up stimuli
    message1.setText(probe1_string)
    message2.setText("1) %s\n2) %s\n3) %s\n4) %s\n5) %s" % probe1_options)
    message1.draw()
    message2.draw()
    win.logOnFlip(level=logging.EXP, msg="Probe 1")
    win.flip()

    # get response
    key1 = event.waitKeys(keyList=["1", "2", "3", "4", "5", "q", "Escape"], timeStamped=trialClock)

    # reset clock
    trialClock.reset()
    # set up stimuli
    message1.setText(probe2_string)
    message2.setText("1) %s\n2) %s\n3) %s\n4) %s\n5) %s" % probe2_options)
    message1.draw()
    message2.draw()
    win.logOnFlip(level=logging.EXP, msg="Probe 2")
    win.flip()

    # get response
    key2 = event.waitKeys(keyList=["1", "2", "3", "4", "5", "q", "Escape"], timeStamped=trialClock)

    # return results
    return (key1[0], key2[0])
开发者ID:djangraw,项目名称:PsychoPyParadigms,代码行数:29,代码来源:SequenceLearningTask.py

示例15: nPaired

def nPaired (fi, nback_no, window, seq, dura, trial_no=None, adaptive=False):

    #data structures
    audicode=['C','D','E','F']
    colorcode=['red','blue','green','yellow']
    trial_no=len(seq)
    ready=visual.TextStim(window,'ready?', color=(1.0,1.0,1.0))
    infoloop=['Press return/enter to continue',
             'This is the paired 2-back test',
             'You will see a series that contains both audio tones and coloured squares together',
             'In this test, the same colour/tone pair is always presented together',
             'Press L if the colour/tone pair matches the pair two steps back']
    vstimlist=[];astimlist=[]
    target=[0,0]
    n=0

    #create two stimuli lists and mark down target trials
    for i in seq:
        vstimlist.append(visual.Rect(window,width=100.0,height=100.0,lineColor=colorcode[i],fillColor=colorcode[i], pos=(0,0)))
        astimlist.append(sound.Sound(audicode[i],octave=4, sampleRate=44100, secs=dura,bits=8))
        if n > nback_no-1:
            #if the event match with n events ago (n specified by 'nback_no')
            #mark it as a target trial
            if i==seq[n-nback_no]:
                target.append(1)
            else:
                target.append(0)
        n = n+1
    infolooper(infoloop,window) #present basic test info for participant (what test, etc)
    ready.draw()
    window.flip()
    event.waitKeys(keyList=['return'])
    n=0
    #play/draw stimuli and record response time
    for vtrial in vstimlist:
        response=None; hit=None; time=None
        vtrial.draw()
        astimlist[n].play()
        starttime=window.flip()
        #each stimulus is displayed for the duration specified
        response=event.waitKeys(maxWait=dura-(1/120.0),keyList=['l'],timeStamped=True)
        while(logging.defaultClock.getTime() - starttime) <= dura:
            pass
        if response!=None:
            if target[n]==1: #if target trials and get keypress, set 'hit' to true
                hit=True
            else: #if not target trials but get keypress, set 'hit' to false
                hit=False
            time=response[0][1]-starttime #record RT for any keypress

        window.flip()

#output includes: condition, trial number, whether it's target, whether a hit, RT
        fi.writerow(['%s, %d, %s, %s, %s\n'%('paired', n+1, str(target[n]==1), str(hit), str(time))])
        n = n+1
        core.wait(0.5)
    
    #fi.writerow(['Testing sequence ', seq])
    fi.writerow([])
开发者ID:am4002,项目名称:behav_trial,代码行数:59,代码来源:nback_tests.py


注:本文中的psychopy.event.waitKeys函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。