本文整理汇总了Python中psychopy.event._onPygletKey函数的典型用法代码示例。如果您正苦于以下问题:Python _onPygletKey函数的具体用法?Python _onPygletKey怎么用?Python _onPygletKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_onPygletKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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)
示例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()
示例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
示例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)
示例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)
示例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
示例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']
示例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)
示例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)
示例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()
示例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
示例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
示例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 = []
示例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 = []