![]() ![]() corr = 0 # was the resp correct this trial? (0=no, 1=yes) self. status = NOT_STARTED # Initiate containers for storing responses self. warning ( "keyboard.Keyboard already using ' %s ' backend. _backend is None and backend in : Keyboard. """ _backend = None _iohubKeyboard = None _iohubOffset = 0.0 _ptbOffset = 0.0 def _init_ ( self, device =- 1, bufferSize = 10000, waitForStart = False, clock = None, backend = None ): """Create the device (default keyboard or select one) Parameters - device: int or dict On Linux/Mac this can be a device index or a dict containing the device info (as from :func:`getKeyboards`) or -1 for all devices acting as a unified Keyboard bufferSize: int How many keys to store in the buffer (before dropping older ones) waitForStart: bool (default False) Normally we'll start polling the Keyboard at all times but you could choose not to do that and start/stop manually instead by setting this to True """ global havePTB if self. ![]() class Keyboard : """The Keyboard class provides access to the Psychtoolbox KbQueue-based calls on **Python3 64-bit** with fall-back to `event.getKeys` on legacy systems. _create_queue = _replacement_create_queue # On win32, flush_type must be 0 or events can get flushed before being processed _ptb_flush_type = 0 device_number, None, 0, num_slots, flags, win_handle ) # replace the broken function with ours hid. platform = 'win32' : from psychtoolbox import PsychHID # make a new function where we set default win_handle to be None instead of 0 def _replacement_create_queue ( self, num_slots = 10000, flags = 0, win_handle = None ): PsychHID ( 'KbQueueCreate', self. # Also set ptb _ptb_flush_type to 0 for win32. Using event module for keyboard component." )) from psychopy import event havePTB = False defaultBufferSize = 10000 # default ptb flush_type, used by macOS & linux _ptb_flush_type = 1 # monkey-patch bug in PTB keyboard where winHandle=0 is documented but crashes. from _future_ import absolute_import, division, print_function from collections import deque import sys import copy import re import psychopy.clock from psychopy import logging from nstants import NOT_STARTED import time try : import psychtoolbox as ptb from psychtoolbox import hid havePTB = True except ImportError as err : logging. # Distributed under the terms of the GNU General Public License (GPL). code-block:: python from psychopy.hardware import keyboard from psychopy import core kb = keyboard.Keyboard() # during your trial kb.clock.reset() # when you want to start the timer from keys = kb.getKeys(, waitRelease=True) if 'quit' in keys: core.quit() for key in keys: print(key.name, key.rt, key.duration) """ # Part of the PsychoPy library # Copyright (C) 2002-2018 Jonathan Peirce (C) 2019-2022 Open Science Tools Ltd. The new calls have several advantages: - the polling is performed and timestamped asynchronously with the main thread so that times relate to when the key was pressed, not when the call was made - the polling is direct to the USB HID library in C, which is faster than waiting for the operating system to poll and interpret those same packets - we also detect the KeyUp events and therefore provide the option of returning keypress duration - on Linux and Mac you can also distinguish between different keyboard devices (see :func:`getKeyboards`) This library makes use, where possible of the same low-level asynchronous hardware polling as in `Psychtoolbox `_. On 32 bit installations and Python2 it reverts to the older :func:`` calls. Psychtoolbox versus event.getKeys - On 64 bits Python3 installations it provides access to the `Psychtoolbox kbQueue `_ series of functions using the same compiled C code (available in python-psychtoolbox lib). #!/usr/bin/env python # -*- coding: utf-8 -*- """To handle input from keyboard (supersedes event.getKeys) The Keyboard class was new in PsychoPy 3.1 and replaces the older `event.getKeys()` calls. ![]()
0 Comments
Leave a Reply. |