• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python event.waitKeys函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: show_message_page

    def show_message_page(self, window, message, duration=2, block=False, release_key=None):
        visual.TextStim(win=window, text=message, pos=(0, 0), color='White').draw()
        window.update()

        if block:
            event.waitKeys(keyList=None if release_key is None else [release_key])
        else:
            core.wait(duration)
开发者ID:hosseinkhani,项目名称:Dwarf,代码行数:8,代码来源:dwarf01.py


示例17: send

	def send(self, txt, wait=False):
		print txt
		#if wait == True:
			#txt += "\nPress a key to continue."
		self.txt.setText(txt)
		self.txt.draw()
		self.win.flip()
		if wait	== True:
			event.waitKeys()
开发者ID:jchen53,项目名称:Symbolic_NonSymbolic_Representation,代码行数:9,代码来源:common.py


示例18: wait_for_key

def wait_for_key(keys):
    '''Wait for a key that is in a set of keys
    to be pressed before proceeding.

    Args:
    keys - A list or tuple of keys.
    '''
    event.clearEvents()
    event.waitKeys(keyList=keys)
开发者ID:Nimakhin,项目名称:psychopy-project-template,代码行数:9,代码来源:stimulus.py


示例19: textscreen

def textscreen(text, win=stim['window'], exp=exp, auto=False):
	visual.TextStim(win, text=text, units='norm').draw()
	# fix window blendMode:
	win.blendMode = 'add'
	win.flip()
	if not auto:
		event.waitKeys()
	else:
		core.wait(0.1)
开发者ID:mmagnuski,项目名称:exp_CircStim,代码行数:9,代码来源:stimutils.py


示例20: break_checker

def break_checker(window, exp, df, exp_info, logfile, current_trial,
                  qp_refresh_rate=3, plot_fun=None, plot_arg=None, dpi=120,
                  img_name='temp.png', df_save_path='temp.xlsx',
                  show_completed=False, show_correctness=False,
                  use_forced_break=False):

    has_break = current_trial % exp['break after'] == 0
    has_forced_break = current_trial == 214 or current_trial == 428
    if has_break:
        save_df = trim_df(df)
        save_df.to_excel(df_save_path)

    if use_forced_break and has_forced_break:
        forced_break(win=window, auto=exp['debug'], exp_info=exp_info)

    if has_break or (has_forced_break and use_forced_break):
        # remind about the button press mappings
        show_resp_rules(exp=exp, auto=exp['debug'])
        if not show_completed: window.flip()

    if show_completed and (has_break or (has_forced_break and use_forced_break)):
        if show_correctness:
            upper_steps = df.query('step > 2')
            avg_corr = upper_steps.ifcorrect.mean() * 100
            present_break(current_trial, exp=exp, win=window, auto=exp['debug'],
                          correctness=avg_corr)
        else:
            present_break(current_trial, exp=exp, win=window, auto=exp['debug'])
        window.flip()

    if not exp['two screens']:
        # make sure feedback is only shown after the break on one screen
        qp_refresh_rate = 10000

    # visual feedback on parameters probability
    if current_trial % qp_refresh_rate == 0 or has_break:
        try:
            fig = plot_fun(plot_arg)
            fig.savefig(img_name, dpi=dpi)
            plt.close(fig)
            window.winHandle.activate()
        except:
            pass

        if not exp['two screens']:
            win.blendMode = 'avg'

        exp_info.experimenter_plot(img_name)

        if not exp['two screens']:
            event.waitKeys(['f', 'j', 'space', 'return'])
            win.blendMode = 'add'

        # quest plus refresh adds ~ 1 s to ITI so we prefer that
        # it is not predictable when refresh is going to happen
        return sample([3, 4, 5], 1)[0]
    return qp_refresh_rate
开发者ID:mmagnuski,项目名称:exp_CircStim,代码行数:57,代码来源:stimutils.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python components._translate函数代码示例发布时间:2022-05-25
下一篇:
Python event.getKeys函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap