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()
def test_invalid_modifiers(self): """Modifiers must be integers.""" key = 'a' modifiers = None with pytest.raises(ValueError): event._onPygletKey(key, modifiers, emulated=True)
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
def test_invalid_modifiers(self): """Modifiers must be integers.""" key = 'a' modifiers = None with pytest.raises(ValueError): event._onPygletKey(key, modifiers, emulated=True)
def _onPygletKeyPress(symbol, modifier): if modifier: event._onPygletKey(symbol, modifier) global _keyPressBuffer keyTime = core.getTime() key = pyglet.window.key.symbol_string(symbol).lower().lstrip("_").lstrip("NUM_") _keyPressBuffer.append((key, keyTime))
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
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()
def onKey(self, evt, modifiers): """Check for tab key then pass all events to event package.""" if evt is not None: thisKey = pyglet.window.key.symbol_string(evt).lower() if thisKey == 'tab': self.onText('\t') event._onPygletKey(evt, modifiers)
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()
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)
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)
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
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
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)
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']
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)
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']
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)
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()
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)
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)
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)
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=0) # 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()
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()
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
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
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
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 = []
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 = []
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: # avoid cryptic error if int key = "{}".format(key)[0] if type(key) == type(""): event._onPygletKey(symbol=key, modifiers=0, emulated=True) else: logging.error('ResponseEmulator: only keyboard events ' 'are supported') last_onset = onset if self.stopflag: break self.running = False return self
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 = []
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: # avoid cryptic error if int key = "{}".format(key)[0] if type(key) == type(""): event._onPygletKey(symbol=key, modifiers=0, emulated=True) else: logging.error('ResponseEmulator: only keyboard events ' 'are supported') last_onset = onset if self.stopflag: break self.running = False return self
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
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()
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 _vmTesting: assert 0.001 < h[-1][1] < 0.05 # virtual machines not usually great else: assert 0.001 < h[-1][1] < 0.03
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()
def test_keys(self): pytest.skip() # failing on travis-ci if self.win.winType == 'pygame': pytest.skip() event.clearEvents() assert event.getKeys() == [] for k in ['s', 'return']: event.clearEvents() event._onPygletKey(symbol=k, modifiers=None, emulated=True) assert k in event.getKeys() event._onPygletKey(symbol=17, modifiers=None, emulated=False) assert '17' in event.getKeys() event._onPygletKey(symbol=k, modifiers=None, emulated=True) assert k in event.getKeys(timeStamped=True)[0] event._onPygletKey(symbol=k, modifiers=None, emulated=True) event._onPygletKey(symbol='x', modifiers=None, emulated=True) # nontarget assert k in event.getKeys(keyList=[k, 'd']) # waitKeys implicitly clears events, so use a thread to add a delayed key press assert event.waitKeys(maxWait=-1) == None keyThread = DelayedFakeKey(k) keyThread.start() assert event.waitKeys(maxWait=.1) == [k] keyThread = DelayedFakeKey(k) keyThread.start() assert event.waitKeys(maxWait=.1, keyList=[k]) == [k] # test time-stamped waitKeys c = core.Clock() delay = 0.01 keyThread = DelayedFakeKey(k, delay=delay) keyThread.start() result = event.waitKeys(maxWait=.1, keyList=[k], timeStamped=c) assert result[0][0] == k assert result[0][ 1] - delay < .001 # should be ~0 except for execution time
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()
def test_keys(self): pytest.skip() # failing on travis-ci if self.win.winType == 'pygame': pytest.skip() event.clearEvents() assert event.getKeys() == [] for k in ['s', 'return']: event.clearEvents() event._onPygletKey(symbol=k, modifiers=None, emulated=True) assert k in event.getKeys() event._onPygletKey(symbol=17, modifiers=None, emulated=False) assert '17' in event.getKeys() event._onPygletKey(symbol=k, modifiers=None, emulated=True) assert k in event.getKeys(timeStamped=True)[0] event._onPygletKey(symbol=k, modifiers=None, emulated=True) event._onPygletKey(symbol='x', modifiers=None, emulated=True) # nontarget assert k in event.getKeys(keyList=[k, 'd']) # waitKeys implicitly clears events, so use a thread to add a delayed key press assert event.waitKeys(maxWait=-1) == None keyThread = DelayedFakeKey(k) keyThread.start() assert event.waitKeys(maxWait=.1) == [k] keyThread = DelayedFakeKey(k) keyThread.start() assert event.waitKeys(maxWait=.1, keyList=[k]) == [k] # test time-stamped waitKeys c = core.Clock() delay=0.01 keyThread = DelayedFakeKey(k, delay=delay) keyThread.start() result = event.waitKeys(maxWait=.1, keyList=[k], timeStamped=c) assert result[0][0] == k assert result[0][1] - delay < .001 # should be ~0 except for execution time
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(0.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
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
def keyPress(cls, symbol, modifiers=None, emulated=True): event._onPygletKey(symbol=symbol, modifiers=modifiers, emulated=emulated)
def run(self): core.wait(self.delay) event._onPygletKey(symbol=self.key, modifiers=None, emulated=True)
def test_clearEvents_keyboard(self): event._onPygletKey(symbol='x', modifiers=0, emulated=True) event.clearEvents('keyboard') assert not event._keyBuffer
def test_clearEvents_joystick(self): """Keyboard buffer should not be affected. """ event._onPygletKey(symbol='x', modifiers=0, emulated=True) event.clearEvents('joystick') assert event._keyBuffer
def test_keyname(self): """Test that a key name is correctly returned.""" event._onPygletKey('a', 0, emulated=True) keys = event.getKeys() assert len(keys) == 1 assert keys[0] == 'a'
def test_keyname(self): """Test that a key name is correctly returned.""" event._onPygletKey('a', 0, emulated=True) keys = event.getKeys() assert len(keys) == 1 assert keys[0] == 'a'
def run(self): core.wait(self.delay) event._onPygletKey(symbol=self.key, modifiers=None, emulated=True)
def run(self): core.wait(self.delay) [event._onPygletKey(key, modifiers=self.modifiers, emulated=True) for key in self.keys]