Raspberry Pi: Can't grab keyboard input

Hi all,

I can’t seem to get keyboard events with SDL2 + Raspberry Pi. I’ve tried running in the console as well as in X. I’m in the input/tty group. All input seems to go through to X or the console and a mouse cursor shows up (in console or X) in the top left corner.

Here’s some sample C code that fills with random color and quits on SDL_KEYDOWN, along with the config.log from when I built SDL2. Anything missing here? Should I file a bug?

https://gist.github.com/magaio/76d26b0be8ca360366ab

I also notice these symptoms using PySDL2.

Try installing and running “evtest”, and see if you get events from that.
Run it on the console with the X server stopped.
If you do get events, lets say from the device at /dev/input/event3, you
can also try:

udevadm info --path=/sys/class/input/event3 | grep ID_INPUT_KEYBOARD

You should get:

E: ID_INPUT_KEYBOARD=1

If any of that fails, SDL won’t recognize the keyboard. If everything works
and you still don’t get keyboard events, let me know.

2014-07-03 1:28 GMT-03:00 accumulator :> Hi all,

I can’t seem to get keyboard events with SDL2 + Raspberry Pi. I’ve tried
running in the console as well as in X. I’m in the input/tty group. All
input seems to go through to X or the console and a mouse cursor shows up
(in console or X) in the top left corner.

Here’s some sample C code that fills with random color and quits on
SDL_KEYDOWN, along with the config.log from when I built SDL2. Anything
missing here? Should I file a bug?

https://gist.github.com/magaio/76d26b0be8ca360366ab

I also notice these symptoms using PySDL2.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.

evtest looks good for both the keyboard and mouse, event0 and event2 respectively.

udevadm info --path=/sys/class/input/event0 shows ID_INPUT_KEYBOARD=1.

event0:

Code:

P: /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.0/input/input0/event0
N: input/event0
S: input/by-id/usb-Cypress_USB_Keyboard-event-kbd
S: input/by-path/platform-bcm2708_usb-usb-0:1.3.2:1.0-event-kbd
E: BACKSPACE=guess
E: DEVLINKS=/dev/input/by-id/usb-Cypress_USB_Keyboard-event-kbd /dev/input/by-path/platform-bcm2708_usb-usb-0:1.3.2:1.0-event-kbd
E: DEVNAME=/dev/input/event0
E: DEVPATH=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.0/input/input0/event0
E: ID_BUS=usb
E: ID_INPUT=1
E: ID_INPUT_KEY=1
E: ID_INPUT_KEYBOARD=1
E: ID_MODEL=USB_Keyboard
E: ID_MODEL_ENC=USB\x20Keyboard
E: ID_MODEL_ID=0101
E: ID_PATH=platform-bcm2708_usb-usb-0:1.3.2:1.0
E: ID_PATH_TAG=platform-bcm2708_usb-usb-0_1_3_2_1_0
E: ID_REVISION=0001
E: ID_SERIAL=Cypress_USB_Keyboard
E: ID_TYPE=hid
E: ID_USB_DRIVER=usbhid
E: ID_USB_INTERFACES=:030101:030000:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Cypress
E: ID_VENDOR_ENC=Cypress
E: ID_VENDOR_ID=04b4
E: MAJOR=13
E: MINOR=64
E: SUBSYSTEM=input
E: UDEV_LOG=3
E: USEC_INITIALIZED=5513306
E: XKBLAYOUT=us
E: XKBMODEL=pc101
E: XKBOPTIONS=terminate:ctrl_alt_bksp

event1:

Code:

P: /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.1/input/input1/event1
N: input/event1
S: input/by-id/usb-Cypress_USB_Keyboard-event-if01
S: input/by-path/platform-bcm2708_usb-usb-0:1.3.2:1.1-event
E: BACKSPACE=guess
E: DEVLINKS=/dev/input/by-id/usb-Cypress_USB_Keyboard-event-if01 /dev/input/by-path/platform-bcm2708_usb-usb-0:1.3.2:1.1-event
E: DEVNAME=/dev/input/event1
E: DEVPATH=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.1/input/input1/event1
E: ID_BUS=usb
E: ID_INPUT=1
E: ID_INPUT_KEY=1
E: ID_MODEL=USB_Keyboard
E: ID_MODEL_ENC=USB\x20Keyboard
E: ID_MODEL_ID=0101
E: ID_PATH=platform-bcm2708_usb-usb-0:1.3.2:1.1
E: ID_PATH_TAG=platform-bcm2708_usb-usb-0_1_3_2_1_1
E: ID_REVISION=0001
E: ID_SERIAL=Cypress_USB_Keyboard
E: ID_TYPE=hid
E: ID_USB_DRIVER=usbhid
E: ID_USB_INTERFACES=:030101:030000:
E: ID_USB_INTERFACE_NUM=01
E: ID_VENDOR=Cypress
E: ID_VENDOR_ENC=Cypress
E: ID_VENDOR_ID=04b4
E: MAJOR=13
E: MINOR=65
E: SUBSYSTEM=input
E: UDEV_LOG=3
E: USEC_INITIALIZED=5957295
E: XKBLAYOUT=us
E: XKBMODEL=pc101
E: XKBOPTIONS=terminate:ctrl_alt_bksp

event2:

Code:

P: /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/input/input2/event2
N: input/event2
S: input/by-id/usb-Microsoft_Microsoft_5-Button_Mouse_with_IntelliEye_TM_-event-mouse
S: input/by-path/platform-bcm2708_usb-usb-0:1.3.3:1.0-event-mouse
E: DEVLINKS=/dev/input/by-id/usb-Microsoft_Microsoft_5-Button_Mouse_with_IntelliEye_TM_-event-mouse /dev/input/by-path/platform-bcm2708_usb-usb-0:1.3.3:1.0-event-mouse
E: DEVNAME=/dev/input/event2
E: DEVPATH=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/input/input2/event2
E: ID_BUS=usb
E: ID_INPUT=1
E: ID_INPUT_MOUSE=1
E: ID_MODEL=Microsoft_5-Button_Mouse_with_IntelliEye_TM_
E: ID_MODEL_ENC=Microsoft\x205-Button\x20Mouse\x20with\x20IntelliEye\x28TM\x29
E: ID_MODEL_ID=0047
E: ID_PATH=platform-bcm2708_usb-usb-0:1.3.3:1.0
E: ID_PATH_TAG=platform-bcm2708_usb-usb-0_1_3_3_1_0
E: ID_REVISION=0300
E: ID_SERIAL=Microsoft_Microsoft_5-Button_Mouse_with_IntelliEye_TM_
E: ID_TYPE=hid
E: ID_USB_DRIVER=usbhid
E: ID_USB_INTERFACES=:030102:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Microsoft
E: ID_VENDOR_ENC=Microsoft
E: ID_VENDOR_ID=045e
E: MAJOR=13
E: MINOR=66
E: SUBSYSTEM=input
E: UDEV_LOG=3
E: USEC_INITIALIZED=5899274

Did you build SDL yourself? If you are running evtest in the same way (same
user, etc) than your SDL app, and evtest works, SDL should work too if it
has EVDEV and UDEV support enabled.

2014-07-04 14:27 GMT-03:00 accumulator :> evtest looks good for both the keyboard and mouse, event0 and event2

respectively.

udevadm info --path=/sys/class/input/event0 shows ID_INPUT_KEYBOARD=1.

event0:

Code:

P:
/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.0/input/input0/event0
N: input/event0
S: input/by-id/usb-Cypress_USB_Keyboard-event-kbd
S: input/by-path/platform-bcm2708_usb-usb-0:1.3.2:1.0-event-kbd
E: BACKSPACE=guess
E: DEVLINKS=/dev/input/by-id/usb-Cypress_USB_Keyboard-event-kbd
/dev/input/by-path/platform-bcm2708_usb-usb-0:1.3.2:1.0-event-kbd
E: DEVNAME=/dev/input/event0
E:
DEVPATH=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.0/input/input0/event0
E: ID_BUS=usb
E: ID_INPUT=1
E: ID_INPUT_KEY=1
E: ID_INPUT_KEYBOARD=1
E: ID_MODEL=USB_Keyboard
E: ID_MODEL_ENC=USB\x20Keyboard
E: ID_MODEL_ID=0101
E: ID_PATH=platform-bcm2708_usb-usb-0:1.3.2:1.0
E: ID_PATH_TAG=platform-bcm2708_usb-usb-0_1_3_2_1_0
E: ID_REVISION=0001
E: ID_SERIAL=Cypress_USB_Keyboard
E: ID_TYPE=hid
E: ID_USB_DRIVER=usbhid
E: ID_USB_INTERFACES=:030101:030000:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Cypress
E: ID_VENDOR_ENC=Cypress
E: ID_VENDOR_ID=04b4
E: MAJOR=13
E: MINOR=64
E: SUBSYSTEM=input
E: UDEV_LOG=3
E: USEC_INITIALIZED=5513306
E: XKBLAYOUT=us
E: XKBMODEL=pc101
E: XKBOPTIONS=terminate:ctrl_alt_bksp

event1:

Code:

P:
/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.1/input/input1/event1
N: input/event1
S: input/by-id/usb-Cypress_USB_Keyboard-event-if01
S: input/by-path/platform-bcm2708_usb-usb-0:1.3.2:1.1-event
E: BACKSPACE=guess
E: DEVLINKS=/dev/input/by-id/usb-Cypress_USB_Keyboard-event-if01
/dev/input/by-path/platform-bcm2708_usb-usb-0:1.3.2:1.1-event
E: DEVNAME=/dev/input/event1
E:
DEVPATH=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.1/input/input1/event1
E: ID_BUS=usb
E: ID_INPUT=1
E: ID_INPUT_KEY=1
E: ID_MODEL=USB_Keyboard
E: ID_MODEL_ENC=USB\x20Keyboard
E: ID_MODEL_ID=0101
E: ID_PATH=platform-bcm2708_usb-usb-0:1.3.2:1.1
E: ID_PATH_TAG=platform-bcm2708_usb-usb-0_1_3_2_1_1
E: ID_REVISION=0001
E: ID_SERIAL=Cypress_USB_Keyboard
E: ID_TYPE=hid
E: ID_USB_DRIVER=usbhid
E: ID_USB_INTERFACES=:030101:030000:
E: ID_USB_INTERFACE_NUM=01
E: ID_VENDOR=Cypress
E: ID_VENDOR_ENC=Cypress
E: ID_VENDOR_ID=04b4
E: MAJOR=13
E: MINOR=65
E: SUBSYSTEM=input
E: UDEV_LOG=3
E: USEC_INITIALIZED=5957295
E: XKBLAYOUT=us
E: XKBMODEL=pc101
E: XKBOPTIONS=terminate:ctrl_alt_bksp

event2:

Code:

P:
/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/input/input2/event2
N: input/event2
S:
input/by-id/usb-Microsoft_Microsoft_5-Button_Mouse_with_IntelliEye_TM_-event-mouse
S: input/by-path/platform-bcm2708_usb-usb-0:1.3.3:1.0-event-mouse
E:
DEVLINKS=/dev/input/by-id/usb-Microsoft_Microsoft_5-Button_Mouse_with_IntelliEye_TM_-event-mouse
/dev/input/by-path/platform-bcm2708_usb-usb-0:1.3.3:1.0-event-mouse
E: DEVNAME=/dev/input/event2
E:
DEVPATH=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/input/input2/event2
E: ID_BUS=usb
E: ID_INPUT=1
E: ID_INPUT_MOUSE=1
E: ID_MODEL=Microsoft_5-Button_Mouse_with_IntelliEye_TM_
E:
ID_MODEL_ENC=Microsoft\x205-Button\x20Mouse\x20with\x20IntelliEye\x28TM\x29
E: ID_MODEL_ID=0047
E: ID_PATH=platform-bcm2708_usb-usb-0:1.3.3:1.0
E: ID_PATH_TAG=platform-bcm2708_usb-usb-0_1_3_3_1_0
E: ID_REVISION=0300
E: ID_SERIAL=Microsoft_Microsoft_5-Button_Mouse_with_IntelliEye_TM_
E: ID_TYPE=hid
E: ID_USB_DRIVER=usbhid
E: ID_USB_INTERFACES=:030102:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Microsoft
E: ID_VENDOR_ENC=Microsoft
E: ID_VENDOR_ID=045e
E: MAJOR=13
E: MINOR=66
E: SUBSYSTEM=input
E: UDEV_LOG=3
E: USEC_INITIALIZED=5899274


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.

I did build it myself, yes. This was just a fresh, vanilla Raspbian install. I attached my config.log in my first post to see if anyone might catch something I overlooked. I’m pretty sure I installed the correct -dev packages before configuring and building. I wouldn’t need explicit configure flags to turn it on, right? It looks like SDL_INPUT_LINUXEV got defined during configure, which I would think would be enough to turn it on during build.

You don’t have libudev-dev installed:

configure:21254: checking libudev.h usability
configure:21254: gcc -c -g -O2 -Iinclude
-I/home/pi/Downloads/SDL2-2.0.3/include -I/opt/vc/include
-I/opt/vc/include/interface/vcos/pthreads
-I/opt/vc/include/interface/vmcs_host/linux -Iinclude
-I/home/pi/Downloads/SDL2-2.0.3/include conftest.c >&5
conftest.c:146:21: fatal error: libudev.h: No such file or directory

Try installing it and build again.

2014-07-04 15:33 GMT-03:00 accumulator :> I did build it myself, yes. This was just a fresh, vanilla Raspbian

install. I attached my config.log in my first post to see if anyone might
catch something I overlooked. I’m pretty sure I installed the correct -dev
packages before configuring and building. I wouldn’t need explicit
configure flags to turn it on, right? It looks like SDL_INPUT_LINUXEV got
defined during configure, which I would think would be enough to turn it on
during build.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.

2014-07-04 15:33 GMT-03:00 accumulator :

I did build it myself, yes. This was just a fresh, vanilla Raspbian
install. I attached my config.log in my first post to see if anyone might
catch something I overlooked. I’m pretty sure I installed the correct -dev
packages before configuring and building. I wouldn’t need explicit
configure flags to turn it on, right? It looks like SDL_INPUT_LINUXEV got
defined during configure, which I would think would be enough to turn it on
during build.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.

Weird, how did I miss that? Surely configure would’ve reported and returned non-zero at the end?

Anyway, when I went to install libudev-dev, it was already installed, so I probably have mixed some steps up somewhere. I’ll remove my build directory and try from scratch and report back.

Thanks -

Gabriel - case closed! After a clean rebuild and install, my example works correctly and exits on keydown. Incidentally, the mouse cursor tracks my mouse at the console - way cool. :slight_smile:

I think what happened was this:

  1. I did an initial ./configure without libevdev-dev or libudev-dev installed
  2. I realized I needed these libraries but only installed libevdev-dev.
  3. Reran ./configure and missed the error message (but I feel like it exited with 0).
  4. Another make and make install

It seemed that having libevdev-dev installed defined SDL_INPUT_LINUXEV but somehow safely built without libudev support. I’ll try to reproduce the conditions and file a bug if necessary.

Thanks a lot for taking the time to help me diagnose.