Cannot detect key presses on Ubuntu

Hi all! I’m using Ubuntu 24.04, python 3.10.13 and the lastest Psychopy I installed with pip install wxpython-4.2.5-cp310-cp310-linux_x86_64.whl and pip install

The problem is that I cannot get any key press with my

kb = keyboard.Keyboard(backend='ptb')
kb.waitKeys(keyList=KEYLIST_DICT["quit"])

And there’s no error message. I also tried a version without the keyList. But again, I didn’t get any responses with any key press.

The same code works perfectly with my Win11 computer.

As I cannot find any useful information online, I asked AI for help. Per Gemini’s suggestion, I tried the following: (None of them worked)

  1. Switching from Wayland to X11. (Apparently Ubuntu 26 doesn’t support X11 anymore. So I had to reinstall Ubuntu 24 to do this)
  2. Adding the user to the input and psychtoolbox group, by doing
    sudo usermod -aG input $USER
    sudo groupadd --force psychtoolbox
    sudo usermod -aG psychtoolbox $USER
  3. switching the backend of keyboard.Keyboard between event and ptb.
  4. installing evdev in my conda environment

And of course, clicking on the window to make sure it’s “in the focus”.

None of them solved the problem.

Any idea what is going on and how can I get psychopy to work on Ubuntu?

Thanks!

You’ve written kb.waitKeys(keyList=KEYLIST_DICT["quit"]) Is KEYLIST_DICT a dictionary you’ve created? Does kb.waitKeys(keyList=["q", "space"]) work?

Hi! It’s defined in another script as

KEYLIST_DICT = dict(

    left=["left", "a"],

    right=["right", "d"],

    up=["up", "w"],

    quit=["q"],
)

and it is imported at the start of the main script.

I don’t think that was the cause of the problem, because I’ve also tested it with just kb.waitKeys(), and I couldn’t get any response with any key press.

Just had the same problem. On mine (Slackware) psychtoolbox is imported by psychopy:hardware:keyboard. This fails silently if libjack is not installed. There are a few other threads in the various categories about this. It would be nice, if possible, to be able to

from psychtoolbox import keyboard

assuming that keyboard does not need jack.