Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run():
dev = kbDevices[0]
# KbQueueTest
ptb.WaitSecs('YieldSecs', 1)
keyboard = hid.Keyboard(dev['index'])
# keyboard.queue_create(num_slots=10000) # done implicitly but can redo
# keyboard.start_trapping() # stops keys going to stdout but sketchy!
keyboard.queue_start()
t0 = ptb.GetSecs()
while ptb.GetSecs() < t0+5:
ptb.WaitSecs('YieldSecs', 0.00001)
if keyboard.flush():
evt = keyboard.queue_get_event()
print(evt)
keyboard.queue_stop()
audiodata.dtype);
recording.close() # PsychPortAudio('Close', pahandle);
playback = audio.Stream(freq=Fs, channels=2);
playback.volume = 1.0 # PsychPortAudio('Volume', pahandle, 1);
# Fill in audio matrix for playback:
playback.fill_buffer(audiodata) # PsychPortAudio('FillBuffer', pahandle, audiodata);
# Start playback for one repetition (1), 5 seconds from now, wait for sound onset:
playback.start(1, GetSecs() + 1, 1) # PsychPortAudio('Start', pahandle, 1, GetSecs() + 1, 1)
# Go into a loop that prints playback status once a second, as long as playback
# is active:
keyboard = hid.Keyboard()
info = playback.status # PsychPortAudio('GetStatus', pahandle);
print(info, ' Spec ', info['Active']);
while playback.status['Active'] and not Keyboard.check()[0]:
WaitSecs('YieldSecs', 1);
# Stop playback:
# [startTime, endPositionSecs, xruns, estStopTime] = PsychPortAudio('Stop', pahandle)
startTime, endPositionSecs, xruns, estStopTime = playback.stop()
print('StartTime', startTime, 'secs. Stop time', estStopTime, 'secs.\n');
# Close sound device:
playback.close() # PsychPortAudio('Close', pahandle);
def __init__(self, bufferSize, kb_id):
self.bufferSize = bufferSize
self._evts = deque()
# create the PTB keyboard object and corresponding queue
allInds, names, keyboards = hid.get_keyboard_indices()
self._keys = []
self._keysStillDown = []
if kb_id == -1:
self.dev = hid.Keyboard() # a PTB keyboard object
else:
self.dev = hid.Keyboard(kb_id) # a PTB keyboard object
self.dev._create_queue(bufferSize)
self.keys = [] # the key(s) pressed
self.corr = 0 # was the resp correct this trial? (0=no, 1=yes)
self.rt = [] # response time(s)
self.time = [] # Epoch
if clock:
self.clock = clock
else:
self.clock = psychopy.clock.Clock()
if havePTB:
# get the necessary keyboard buffer(s)
if sys.platform=='win32':
self._ids = [-1] # no indexing possible so get the combo keyboard
else:
allInds, allNames, allKBs = hid.get_keyboard_indices()
if device==-1:
self._ids = allInds
elif type(device) in [list, tuple]:
self._ids = device
else:
self._ids = [device]
self._buffers = {}
self._devs = {}
for devId in self._ids:
# now we have a list of device IDs to monitor
if devId==-1 or devId in allInds:
buffer = _keyBuffers.getBuffer(devId, bufferSize)
self._buffers[devId] = buffer
self._devs[devId] = buffer.dev