psychopy.org | Reference | Downloads | Github

Can't use the new keyboard component (from Psychtoolbox)

Hi,
I installed the new standalone PsychoPy 3.1.0 for 64 bits windows (Python 3.6-note that my OS is windows 10, and the computer is a dell xps15 laptop). I created a basic Stroop experiment to check if everything was working properly and got this error message:

WARNING Import Error: No module named 'psychtoolbox'. Using event module for keyboard component.

I then tried to run this code example from the psychopy.hardware.keyboard class:

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(['right', 'left', 'quit'], waitDuration=True)
if 'quit' in keys:
    core.quit()
for key in keys:
    print(key.name, key.rt, key.duration)

(the waitDuration argument doesn’t exist, so I supect it’s a typo and you guys meant waitForStart instead -I removed it)
The code doesn’t work and I get the same error message.
@jon @Michael it looks like PsychoPy reverts to the older event.getKeys() function which appears to be a bug because I am using python 3.6 on a 64 bits windows. Unless I missed something, I don’t see any psychtoolbox module in the PsychoPy folder. That might be the issue…
Thanks for the help,
Mat

Hi @Servant_Mathieu, I have logged this issue on GitHub, please follow the issue for an update. I think that the module just needs to be downloaded because it does not appear to be part of the distribution. The issue is below. Alternatively, you could add the module manually, rather than waiting for the fix. To do this, see Adding external modules to Standalone PsychoPy. You can download the Psychtoolbox module here.

For the GitHub issue:

Hi @dvbridges adding the module manually solved the issue.

1 Like

@dvbridges to be sure I understand correctly the function: key.rt is determined by the key press, and key.duration is the latency between the key press and the release of that key. If this is correct, why is the key.duration a negative value? In addition, I don’t understand the waitRelease argument. Setting this argument to True does not return “any “incomplete” keypress”. How can a keypress be incomplete?
Thanks for the help

Sorry that psychtoolbox lib wasn’t included in the win64 standalone. It is in the next release (3.1.1).

The idea of waitRelease is that, in a scenario where you want a duration to be reported we have to decide what to do about keys that are still currently held down (the press is incomplete - we don’t yet have all the data for those).

With waitRelease=true only key presses that have been completed are returned, so all are guaranteed to have a duration value, whereas with waitRelease=False a key that is still held down will be reported but simply won’t have a duration value.

from psychopy import visual, event, core
from psychopy.hardware import keyboard


kb = keyboard.Keyboard()

win = visual.Window()
msg = visual.TextStim(win, 'Using WaitKeys()\n\nPress a key!', wrapWidth=1.5)
msg.setAutoDraw(True)
instruct = visual.TextStim(win, pos=(0,-0.8),
    text='Press Esc to move on (to test getKeys)', wrapWidth=1.5)
instruct.setAutoDraw(True)
win.flip()

msg.text = 'Press and hold a key, or press one quickly'
instruct.text='Press Esc to finish'
while continuing:
    core.wait(0.5)
    
    complKeys = kb.getKeys(waitRelease=True)  # don't clear - keep for next
    remainingKeys = kb.getKeys(waitRelease=False)
    txt = ''
    
    if complKeys:
        txt += 'Complete presses:\n'
        for key in complKeys:
            txt += ('key: {}, RT={}, duration={}\n'
                    .format(key.name, key.rt, key.duration))
    if remainingKeys:
        txt += '\nKeys still down:\n'
        for key in remainingKeys:
            print(dir(key))
            txt += ('key: {}, RT={}, duration={}\n'
                    .format(key.name, key.rt, key.duration))
            if key.name=='escape':
                continuing = False
    if txt:
        msg.text = txt

    win.flip()

Actually though I think the timing looks wrong here! I’m getting negative durations!! :-/

Ahah no worries. Yep durations are negative but they look correct, so I guess it’s just a sign issue.