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

Python event._onPygletKey函数代码示例

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

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



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

示例1: test_key_presses

    def test_key_presses(self):
        # simulated keys are not being picked up in draw:

        r = copy.copy(self.r)
        r.markerPlaced = True

        r.mouseOnly = False
        event._onPygletKey(symbol='tab', modifiers=None, emulated=True)
        r.draw()

        r.respKeys = ['s']
        r.enableRespKeys = True
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.draw()

        # test move left, move right:
        r = RatingScale(self.win, markerStart=3, autoLog=False)
        assert r.markerPlacedAt == 2
        event._onPygletKey(symbol='left', modifiers=None, emulated=True)
        r.draw()
        assert r.markerPlaced  # and r.markerPlacedBySubject
        #assert r.markerPlacedAt == 1
        event._onPygletKey(symbol='right', modifiers=None, emulated=True)
        r.draw()
        #assert r.markerPlacedAt == 2

        r.acceptKeys = ['s']
        r.beyondMinTime = True
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.draw()
开发者ID:devinbarry,项目名称:psychopy,代码行数:30,代码来源:test_ratingScale.py


示例2: test_invalid_modifiers

    def test_invalid_modifiers(self):
        """Modifiers must be integers."""
        key = 'a'
        modifiers = None

        with pytest.raises(ValueError):
            event._onPygletKey(key, modifiers, emulated=True)
开发者ID:dgfitch,项目名称:psychopy,代码行数:7,代码来源:test_keyboard_events.py


示例3: getEvents

 def getEvents(self, returnRaw=False, asKeys=False):
     """Returns a list of unique events (one event per button pressed)
     and also stores a copy of the full list of events since last getEvents() 
     (stored as ForpBox.rawEvts)
     
     `returnRaw` :
         return (not just store) the full event list
         
     `asKeys` :
         If True, will also emulate pyglet keyboard events, so that button 1 will
         register as a keyboard event with value "1", and as such will be detectable
         using `event.getKeys()`
     """
     nToGet = self.port.inWaiting()
     evtStr = self.port.read(nToGet)
     self.rawEvts=[]
     #for each character convert to an ordinal int value (numpy the ascii chr)
     for thisChr in evtStr:
         self.rawEvts.append(ord(thisChr))
         if asKeys:
             event._onPygletKey(symbol=ord(thisChr), modifiers=None)
             # better as: emulated='fORP_bbox_asKey', but need to adjust event._onPygletKey
             # and the symbol conversion pyglet.window.key.symbol_string(symbol).lower()
     #return the abbreviated list if necess
     if returnRaw: 
         return self.rawEvts
     else:
         return self.getUniqueEvents()
开发者ID:RSharman,项目名称:psychopy,代码行数:28,代码来源:forp.py


示例4: run

 def run(self):
     self.running = True
     if self.skip:
         for i in range(int(self.skip)):
             if self.playSound:  # pragma: no cover
                 self.sound1.play()
                 self.sound2.play()
             # emulate T1 stabilization without data collection
             core.wait(self.TR, hogCPUperiod=0)
     self.clock.reset()
     for vol in range(1, self.volumes + 1):
         if self.playSound:  # pragma: no cover
             self.sound1.play()
             self.sound2.play()
         if self.stopflag:
             break
         # "emit" a sync pulse by placing a key in the buffer:
         event._onPygletKey(symbol=self.sync, modifiers=0,
                            emulated=True)
         # wait for start of next volume, doing our own hogCPU for
         # tighter sync:
         core.wait(self.timesleep - self.hogCPU, hogCPUperiod=0)
         while self.clock.getTime() < vol * self.TR:
             pass  # hogs the CPU for tighter sync
     self.running = False
     return self
开发者ID:flipphillips,项目名称:psychopy,代码行数:26,代码来源:emulator.py


示例5: test_modifiers_and_timestamp

 def test_modifiers_and_timestamp(self):
     """Test that both key modifiers and timestamp are returned"""
     event._onPygletKey('a', MOD_ALT, emulated=True)
     keys = event.getKeys(modifiers=True, timeStamped=True)
     assert len(keys) == 1
     assert len(keys[0]) == 3
     assert keys[0][0] == 'a'
     assert keys[0][1]['alt']
     assert isinstance(keys[0][2], float)
开发者ID:dgfitch,项目名称:psychopy,代码行数:9,代码来源:test_keyboard_events.py


示例6: handleKeys

def handleKeys(key):
    '''Function for handling keys from the handles and using with
    ratingScale...'''
    if key != 191:
        key = str(key)
        event._onPygletKey(symbol=key, modifiers=None, emulated=True)#Buffers the input
        last_state = True # Return true if down
        port.setData(0)
        core.wait(.15)
开发者ID:marsja,项目名称:psypy,代码行数:9,代码来源:CMM_exp_V2_VT15_ENG.py


示例7: test_timestamp

 def test_timestamp(self):
     """Test that a keypress timestamp is correctly returned"""
     event._onPygletKey('a', 0, emulated=True)
     keys = event.getKeys(timeStamped=True)
     assert len(keys) == 1
     assert len(keys[0]) == 2
     assert keys[0][0] == 'a'
     assert isinstance(keys[0][1], float)
     assert keys[0][1] > 0.0
开发者ID:dgfitch,项目名称:psychopy,代码行数:9,代码来源:test_keyboard_events.py


示例8: test_modifiers

 def test_modifiers(self):
     """Test that key modifier flags are correctly returned"""
     event._onPygletKey('a', MOD_CTRL|MOD_SHIFT, emulated=True)
     keys = event.getKeys(modifiers=True)
     assert len(keys) == 1
     assert len(keys[0]) == 2
     assert keys[0][0] == 'a'
     assert keys[0][1]['ctrl']
     assert keys[0][1]['shift']
     assert not keys[0][1]['alt']
开发者ID:dgfitch,项目名称:psychopy,代码行数:10,代码来源:test_keyboard_events.py


示例9: test_german_characters

 def test_german_characters(self):
     """Test that event can handle German characters"""
     # 824633720832 = ö as pyglet symbol string
     # need to use emulated = False to execute the lines that actually
     # fix the German characters handling
     event._onPygletKey(824633720832, 0, emulated=False)
     event._onPygletText('ö', emulated=True)
     keys = event.getKeys(modifiers=False, timeStamped=True)
     assert len(keys) == 1
     assert len(keys[0]) == 2
     assert keys[0][0] == 'ö'
     assert isinstance(keys[0][1], float)
开发者ID:dgfitch,项目名称:psychopy,代码行数:12,代码来源:test_keyboard_events.py


示例10: test_german_characters_with_modifiers

 def test_german_characters_with_modifiers(self):
     """Test that event can handle German characters with modifiers"""
     # 824633720832 = ö as pyglet symbol string
     # need to use emulated = False to execute the lines that actually
     # fix the German characters handling
     event._onPygletKey(824633720832, MOD_SHIFT | MOD_SCROLLLOCK, emulated=False)
     event._onPygletText('ö', emulated=True)
     keys = event.getKeys(modifiers=True, timeStamped=True)
     assert len(keys) == 1
     assert len(keys[0]) == 3
     assert keys[0][0] == 'ö'
     assert keys[0][1]['shift']
     assert keys[0][1]['scrolllock']
     assert isinstance(keys[0][2], float)
开发者ID:dgfitch,项目名称:psychopy,代码行数:14,代码来源:test_keyboard_events.py


示例11: getEvents

    def getEvents(self, returnRaw=False, asKeys=False, allowRepeats=False):
        """Returns a list of unique events (one event per button pressed)
        and also stores a copy of the full list of events since last
        getEvents() (stored as ForpBox.rawEvts)

        `returnRaw` :
            return (not just store) the full event list

        `asKeys` :
            If True, will also emulate pyglet keyboard events, so that
            button 1 will register as a keyboard event with value "1",
            and as such will be detectable using `event.getKeys()`

        `allowRepeats` :
            If True, this will return pressed buttons even if they were held
            down between calls to getEvents(). If the fORP is on the "Eprime"
            setting, you will get a stream of button presses while a button is
            held down. On the "Bitwise" setting, you will get a set of all
            currently pressed buttons every time a button is pressed or
            released.
            This option might be useful if you think your participant may be
            holding the button down before you start checking for presses.
        """
        nToGet = self.port.inWaiting()
        evtStr = self.port.read(nToGet)
        self.rawEvts = []
        self.pressEvents = []
        if allowRepeats:
            self.clearStatus()
        # for each character convert to an ordinal int value (numpy the ascii
        # chr)
        for thisChr in evtStr:
            pressCode = ord(thisChr)
            self.rawEvts.append(pressCode)
            decodedEvents = self._generateEvents(pressCode)
            self.pressEvents += decodedEvents
            if asKeys:
                for code in decodedEvents:
                    event._onPygletKey(symbol=code, modifiers=None)
                    # better as: emulated='fORP_bbox_asKey', but need to
                    # adjust event._onPygletKey and the symbol conversion
                    # pyglet.window.key.symbol_string(symbol).lower()
        # return the abbreviated list if necessary
        if returnRaw:
            return self.rawEvts
        else:
            return self.getUniqueEvents()
开发者ID:DennisEckmeier,项目名称:psychopy,代码行数:47,代码来源:forp.py


示例12: run

 def run(self):
     self.running = True
     self.clock.reset()
     last_onset = 0.000
     # wait until next event requested, and simulate a key press
     for onset, key in self.responses:
         core.wait(float(onset) - last_onset)
         if type(key) == int:
             #log.warning('ResponseEmulator: int converted to str')
             key = str(key)[0]  # avoid cryptic error if int
         if type(key) == str:
             event._onPygletKey(symbol=key, modifiers=None, emulated=True)
         else:
             logging.error('ResponseEmulator: only keyboard events are supported')
         last_onset = onset
         if self.stopflag: break
     self.running = False
开发者ID:tmintz,项目名称:psychopy,代码行数:17,代码来源:emulator.py


示例13: test_waitKeys_clearEvents_False

    def test_waitKeys_clearEvents_False(self):
        keys = ['x', 'y', 'z']
        [event._onPygletKey(symbol=key, modifiers=0, emulated=True)
         for key in keys]

        key_events = event.waitKeys(keyList=keys[1:], clearEvents=False)
        assert 'x' not in key_events
        assert 'y' in key_events
        assert 'z' in key_events
开发者ID:ChenTzuYin,项目名称:psychopy,代码行数:9,代码来源:test_event.py


示例14: test_somelines

    def test_somelines(self):
        r = copy.copy(self.r)
        r.skipKeys = []
        r.mouseOnly = False
        r.enableRespKeys = True
        r.respKeys = ['s']
        r.allKeys = ['s']
        r.tickFromKeyPress = {u's': 1}
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.singleClick = True
        r.beyondMinTime = True
        r.draw()

        r.leftKeys = ['s']
        r.draw()
        r.leftKeys = []
        r.rightKeys = ['s']
        r.draw()
        r.rightKeys = []
开发者ID:devinbarry,项目名称:psychopy,代码行数:19,代码来源:test_ratingScale.py


示例15: test_1019_1029

    def test_1019_1029(self):
        # 1019-1029
        r = RatingScale(self.win)
        r.skipKeys = []
        r.mouseOnly = False
        r.enableRespKeys = True
        r.respKeys = ['s']
        r.allKeys = ['s']
        r.tickFromKeyPress = {u's': 1}
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.singleClick = True
        r.beyondMinTime = True
        r.draw()

        r.leftKeys = ['s']
        r.draw()
        r.leftKeys = []
        r.rightKeys = ['s']
        r.draw()
        r.rightKeys = []
开发者ID:Gianluigi,项目名称:psychopy,代码行数:20,代码来源:test_ratingScale.py


示例16: test_getRating_RT_history

    def test_getRating_RT_history(self):
        # 1139-43
        r = copy.copy(self.r)
        r.status = FINISHED
        r.noResponse = True
        r.timedOut = True
        assert r.getRT() == r.maxTime
        r.timedOut = False
        assert r.getRT() is None
        r.noResponse = False
        assert r.getRT() == r.decisionTime

        r.reset()  # ---------------
        r.noResponse = True
        r.markerPlacedAt = 0
        r.status = FINISHED
        assert r.getRating() is None

        r.status = FINISHED + 1
        assert r.getRating() == 1

        r.precision = 1
        r.choices = ['a', 'b']
        assert r.getRating() == 'b'

        r = RatingScale(self.win, singleClick=True, autoLog=False)
        r.draw()
        core.wait(.001, 0)
        r.acceptKeys = r.allKeys = ['1']
        r.beyondMinTime = True
        event._onPygletKey(symbol='1', modifiers=0, emulated=True)
        r.draw()
        h = r.getHistory()
        assert h[0] == (None, 0)
        assert h[-1][0] == 1
        if _travisTesting:
            assert 0.001 < h[-1][1] < 0.05  # travis virtual machines not great
        else:
            assert 0.001 < h[-1][1] < 0.03
开发者ID:ChenTzuYin,项目名称:psychopy,代码行数:39,代码来源:test_ratingScale.py


示例17: test_draw_conditionals

    def test_draw_conditionals(self):
        r = RatingScale(self.win)

        # 934-40, 944-45 if self.allowTimeOut ....:
        r.allowTimeOut = True
        r.timedOut = False
        r.maxTime = -1
        r.noResponse = False
        r.disappear = True
        r.draw()

        # 1049-1061  if self.myMouse.getPressed()[0]:

        # 1066-1072  if not self.noResponse and self.decisionTime == 0:
        r = RatingScale(self.win)
        r.beyondMinTime = True
        r.showAccept = True
        r.noResponse = False
        r.decisionTime = 0
        r.draw()

        r = RatingScale(self.win, singleClick=True, markerStyle='glow', markerExpansion=-10)
        r.draw()
        #del r.markerPlacedAt  # 989
        #r.draw()

        # 1006
        r = RatingScale(self.win, showAccept=True, choices=['a', 'b'])
        r.showValue = True
        r.markerPlacedAt = 1
        r.markerPlaced = True
        r.draw()
        r.showvalue = False
        r.draw()

        r = RatingScale(self.win, leftKeys=['s'])
        r.markerPlaced = False
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.draw()
开发者ID:Gianluigi,项目名称:psychopy,代码行数:39,代码来源:test_ratingScale.py


示例18: test_draw_conditionals

    def test_draw_conditionals(self):
        r = copy.copy(self.r)

        r.allowTimeOut = True
        r.timedOut = False
        r.maxTime = -1
        r.noResponse = False
        r.disappear = True
        r.draw()

        # miss lines: if self.myMouse.getPressed()[0]:

        r = copy.copy(self.r)
        r.beyondMinTime = True
        r.showAccept = True
        r.noResponse = False
        r.decisionTime = 0
        r.draw()

        r = RatingScale(self.win, singleClick=True, markerStart=1, marker='glow', markerExpansion=-10, autoLog=False)
        r.draw()

        r = RatingScale(self.win, singleClick=True, markerStart=-1, autoLog=False)
        r.draw()

        r = RatingScale(self.win, showAccept=True, choices=['a', 'b'], autoLog=False)
        r.showValue = True
        r.markerPlacedAt = 1
        r.markerPlaced = True
        r.draw()
        r.showvalue = False
        r.draw()

        r = RatingScale(self.win, labels=['a', 'b', 'c'], autoLog=False)
        r = RatingScale(self.win, tickMarks=[1,2,3], labels=None, autoLog=False)
        r = RatingScale(self.win, leftKeys=['s'], autoLog=False)
        r.markerPlaced = False
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.draw()
开发者ID:devinbarry,项目名称:psychopy,代码行数:39,代码来源:test_ratingScale.py


示例19: test_key_presses

    def test_key_presses(self):
        r = RatingScale(self.win)
        r.markerPlaced = True
        r.allKeys = ['s']
        r.markerPlacedAt = 2

        # 1014-1042
        r.mouseOnly = False
        r.skipKeys = ['s']
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.draw()
        r.skipKeys = []

        r.respKeys = ['s']
        r.enableRespKeys = True
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.draw()
        r.respKeys = []

        r = RatingScale(self.win)
        r.markerPlaced = True
        r.allKeys = ['s']
        r.markerPlacedAt = 2
        r.leftKeys = ['s']
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.draw()
        r.leftKeys = []

        r.rightKeys = ['s']
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.draw()
        r.rightKeys = []

        r.acceptKeys = ['s']
        r.beyondMinTime = True
        event._onPygletKey(symbol='s', modifiers=None, emulated=True)
        r.draw()
开发者ID:Gianluigi,项目名称:psychopy,代码行数:37,代码来源:test_ratingScale.py


示例20: test_getRating_RT_history

    def test_getRating_RT_history(self):
        # 1139-43
        r = RatingScale(self.win)
        r.status = FINISHED
        r.noResponse = True
        r.timedOut = True
        assert r.getRT() == r.maxTime
        r.timedOut = False
        assert r.getRT() == None
        r.noResponse = False
        assert r.getRT() == r.decisionTime

        r = RatingScale(self.win, precision=10)
        r.noResponse = True
        r.markerPlacedAt = 0
        r.status = FINISHED
        assert r.getRating() == False

        r.status = FINISHED + 1
        assert r.getRating() == 1

        r.precision = 1
        r.choices = ['a', 'b']
        assert r.getRating() == 'b'

        r = RatingScale(self.win, singleClick=True)
        r.draw()
        core.wait(.001, 0)
        r.acceptKeys = r.allKeys = ['1']
        r.beyondMinTime = True
        event._onPygletKey(symbol='1', modifiers=None, emulated=True)
        r.draw()
        h = r.getHistory()
        assert h[0] == (None, 0)
        assert h[-1][0] == 1
        assert 0.001 < h[-1][1] < 0.03
开发者ID:Gianluigi,项目名称:psychopy,代码行数:36,代码来源:test_ratingScale.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python event.clearEvents函数代码示例发布时间:2022-05-25
下一篇:
Python data.importConditions函数代码示例发布时间: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