Hotplug/multiple keyboard support?


Can I use multiple keyboard or hotplug keyboard on Rpi?
The reason why I need it is I have sensors connected to Arduino Micro which emulated a keyboard. So I can convert sensor input to keystrokes to avoid driver or other low level stuff. However I can not use Keyboard and Arduino at the same time. But I do see some plug/unplug info in terminal.

Is there any way to use 2 or even more keyboards?


Add function code with V0.9.2

Also started a PR on github

ofAppEGLWindow.h (8.8 KB)
ofAppEGLWindow.cpp (68.1 KB)

under Linux you can use more keyboards simultaneously.
when you connect an input device in the folder /dev/input/eventX it adds a separate event for the device.

Hi Kashim,
Yes OpenFrameworks has potential to access multiple keyboard but currently it is only opening the first keyboard it finds.

I’m new to linux so I followed openframeworks’s way by looking into “by-path” folder. Not very efficient but works.

what I mean is not to use the event openFrameworks “void keyPressed(int key) {}”
because in that case you are connected to the “input” of your window.

perhaps it is more correct to use a “hat” that interfaces with all the inputs that are used in the background.

Simple example for faster debugging:

if you try to connect two keyboards to your raspberry you can note that the /dev/input/
are two files event0 and event1.

if you open two terminals on your raspberry and make a “cat” of the devices concerned:

cat /dev/input/event0
cat /dev/input/event1

pressing keys on both keyboards will see a binary output.
image example:

to enter in “c / c ++” to linux input events you can use:

  #include <linux/input.h>

  struct input_event ev_A[64];
  struct input_event ev_B[64];

  int fd_A,fd_B,
  int rd_A,rd_B;
  int value_A,value_B;
  int size_A = sizeof (struct input_event);
  int size_B = sizeof (struct input_event);

  char name[256] = "Unknown";
  char *keyboard_A =  "/dev/input/event0";
  char *keyboard_B =  "/dev/input/event1";


  if ((fd_A = open (keyboard_A, O_RDONLY)) == -1)
         ofLog()<<"Device:"<<keyboard_A<<"  Error !";

  if ((fd_B = open (keyboard_B, O_RDONLY)) == -1)
         ofLog()<<"Device:"<<keyboard_B<<"  Error !";
  ioctl (fd_A, EVIOCGNAME (sizeof (name)), name);

  ioctl (fd_B, EVIOCGNAME (sizeof (name)), name);

update or thread:

  //read keyboard 1
  if ((rd_A = read (fd_A, ev_A, size_A * 64)) < size_A)
          ofLog()<<"Error read()";

  value_A = ev_A[0].value;
  if (value_A != ' ' && ev_A[0].value == 1 && ev_A[0].type == 1){

  //read keyboard 2
  if ((rd_B = read (fd_B, ev, size_B * 64)) < size_B)
          ofLog()<<"Error read()";
  value_B = ev_B[0].value;
  if (value_B != ' ' && ev_B[0].value == 1 && ev_B[0].type == 1){

This code is not tested but is very close to reality, perhaps you have to do some editing…

1 Like