marimo
Posts: 7
Joined: Sun Feb 21, 2021 8:15 am

Re: Use Pi 400 as Pi Keyboard

Tue Feb 23, 2021 10:54 pm

I can't make heads or tails of wireshark or modprobe.

But looking at the snippet of code that you posted earlier in the thread, maybe adding something like this:

[KEY_102ND] = 0x64,

to the code would assign it the right keycode. I figured this out by looking at the values returned by other keys in the list. For example, pressing [KEY_DOWN] returns "value 70051" in the evtest, and for that you have the keycode "[KEY_DOWN] = 0x51"

cleverca22
Posts: 4425
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Wed Feb 24, 2021 12:16 am

marimo wrote:
Tue Feb 23, 2021 10:54 pm
I can't make heads or tails of wireshark or modprobe.

But looking at the snippet of code that you posted earlier in the thread, maybe adding something like this:

[KEY_102ND] = 0x64,

to the code would assign it the right keycode. I figured this out by looking at the values returned by other keys in the list. For example, pressing [KEY_DOWN] returns "value 70051" in the evtest, and for that you have the keycode "[KEY_DOWN] = 0x51"
confusingly, the code on the right side doesnt match the one from evtest
it has to instead be a code from page 53 of https://www.usb.org/sites/default/files ... 1_12v2.pdf

edit:
Screenshot_2021-02-23_20-19-48.png
Screenshot_2021-02-23_20-19-48.png (13.4 KiB) Viewed 2740 times
oh, weird, it is 64!

give this one a try: https://hydra.angeldsis.com/build/105678

marimo
Posts: 7
Joined: Sun Feb 21, 2021 8:15 am

Re: Use Pi 400 as Pi Keyboard

Wed Feb 24, 2021 1:21 am

Awesome! Yep, it's working perfectly now!

Thanks.

User avatar
Gavinmc42
Posts: 6084
Joined: Wed Aug 28, 2013 3:31 am

Re: Use Pi 400 as Pi Keyboard

Wed Feb 24, 2021 1:47 am

I remembered this last night when I was trying to plug a SD card reader into my last USB slot on my Pi400.
Did not fit with all those cables in the way and I had no handy extension cable.
"Gee I wish I had another hub" :idea:
Grabbed my old Pi keyboard, plugged it into the last USB3 port and then plugged the SD card reader into the old keyboard. :D
Probably the biggest USB hub I have used :lol:

Finding useful things to do with Pi hardware.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

cleverca22
Posts: 4425
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Wed Feb 24, 2021 1:56 am

Gavinmc42 wrote:
Wed Feb 24, 2021 1:47 am
I remembered this last night when I was trying to plug a SD card reader into my last USB slot on my Pi400.
Did not fit with all those cables in the way and I had no handy extension cable.
"Gee I wish I had another hub" :idea:
Grabbed my old Pi keyboard, plugged it into the last USB3 port and then plugged the SD card reader into the old keyboard. :D
Probably the biggest USB hub I have used :lol:

Finding useful things to do with Pi hardware.
that reminds me, a more advanced plan i have, is to use a combination of gadgetfs and libusb, to enable forwarding ALL usb devices to the gadet port

then you could use the pi400 as a fully functional usb hub, including down-converting usb3 backwards to usb2, lol

it would also entirely eliminate all of these funky key mapping problems, because it would just be exposing the internal usb keyboard directly as a usb keyboard

ArmainAP
Posts: 1
Joined: Wed Mar 24, 2021 5:28 pm

Re: Use Pi 400 as Pi Keyboard

Wed Mar 24, 2021 5:35 pm

cleverca22 wrote:
Wed Feb 24, 2021 1:56 am
Gavinmc42 wrote:
Wed Feb 24, 2021 1:47 am
I remembered this last night when I was trying to plug a SD card reader into my last USB slot on my Pi400.
Did not fit with all those cables in the way and I had no handy extension cable.
"Gee I wish I had another hub" :idea:
Grabbed my old Pi keyboard, plugged it into the last USB3 port and then plugged the SD card reader into the old keyboard. :D
Probably the biggest USB hub I have used :lol:

Finding useful things to do with Pi hardware.
that reminds me, a more advanced plan i have, is to use a combination of gadgetfs and libusb, to enable forwarding ALL usb devices to the gadet port

then you could use the pi400 as a fully functional usb hub, including down-converting usb3 backwards to usb2, lol

it would also entirely eliminate all of these funky key mapping problems, because it would just be exposing the internal usb keyboard directly as a usb keyboard
Thank you for your RPI400 HID project. I enjoy using my pi as a simple keyboard :)
How is the gadgetfs and libusb implementation coming along? Anyway I might be able to contribute?

shortsking
Posts: 7
Joined: Sun Dec 27, 2020 2:37 pm

Re: Use Pi 400 as Pi Keyboard

Thu Jun 03, 2021 9:46 pm

i've tried to download off of the hydra page, but it says it cant find the directory "/nix/store/2kfhwj3xl9v9qh392brp2vq690sj36mh-rootzip/root.zip"

cleverca22
Posts: 4425
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Fri Jun 04, 2021 12:16 am

shortsking wrote:
Thu Jun 03, 2021 9:46 pm
i've tried to download off of the hydra page, but it says it cant find the directory "/nix/store/2kfhwj3xl9v9qh392brp2vq690sj36mh-rootzip/root.zip"
the latest version is at https://hydra.angeldsis.com/build/105678

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Thu Jul 01, 2021 9:35 am

I got notice of @trejan's pi400kb gist, that does the same thing, and it works wonderful.
Pressing "CTRL+Raspberry" gives keyboard back to Pi400, and pi400kb can be restarted if needed.
Together with a (3in/2out) HDMI switch it is perfect low space solution for using Pi400 keyboard for laptop and Pi400:
(I have 0 issues with Pi400 keyboard some others reported)
viewtopic.php?f=140&t=289934&p=1883962#p1883962
20210701_085338.15%.jpg
20210701_085338.15%.jpg
20210701_085338.15%.jpg (62.12 KiB) Viewed 2086 times
Last edited by HermannSW on Thu Jul 01, 2021 9:31 pm, edited 1 time in total.
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

trejan
Posts: 3622
Joined: Tue Jul 02, 2019 2:28 pm

Re: Use Pi 400 as Pi Keyboard

Thu Jul 01, 2021 2:19 pm

HermannSW wrote:
Thu Jul 01, 2021 9:35 am
I got notice of @trejan's pi400kb gist
Uh. That isn't mine. It was made by Gadgetoid.

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Thu Jul 01, 2021 7:35 pm

trejan wrote:
Thu Jul 01, 2021 2:19 pm
HermannSW wrote:
Thu Jul 01, 2021 9:35 am
I got notice of @trejan's pi400kb gist
Uh. That isn't mine. It was made by Gadgetoid.
Thanks -- I corrected in the postings affected.

I wanted to have gist that builds cleanly according README.md, without prebuilt binary.
So I forked Gadgetoid's gist:
https://gist.github.com/Hermann-SW/19c7 ... 89de2b0a60

I removed all unnecessary stuff (bcm2835, lua and serialport libs are not needed, remove -L in Makefile and includes in C code). I removed the prebuilt binary as well (that worked only via "git clone" and commit+push. Finally I updated README.md with instructions how to build step by step without issues.

Only library that is needed is libusbgx, that is all in README.md to get and build it:
Clone libusbgx somewhere and build according INSTALL, including "sudo make install"
https://github.com/linux-usb-gadgets/libusbgx

P.S:
I copied self-built "pi400" to /usr/local/bin and use now "laptop" alias to use Pi400 keyboard for laptop:

Code: Select all

pi@raspberrypi400:~ $ tail -1 ~/.bashrc
alias laptop="sudo pi400 2>/dev/null >/dev/null"
pi@raspberrypi400:~ $ 
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Thu Jul 01, 2021 10:57 pm

Nice, others have solved how to create a HID mouse gadget.

HeadMouse project shows how to setup the device (bash script!):
https://github.com/doudulac/HeadMouse-P ... gadgets.sh

And how to move mouse relative or absolute (Python):
https://github.com/doudulac/HeadMouse-P ... e.py#L1016

Now need to find how to capture mouse events from mouse/trackball connected to Pi and combine to "pi400ms" mouse driver ... then I could connect trackball to the Pi400 and use for Pi400 as well as laptop.
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Thu Jul 01, 2021 11:32 pm

Not that difficult, did need to add missing closing angle bracket, but then "/dev/input/event0" provides mouse events (libx11-dev needs to be installed):
https://stackoverflow.com/questions/115 ... x#11520306

Code: Select all

pi@raspberrypi400:~/pi400kb $ gcc ms_pos.c -lX11
pi@raspberrypi400:~/pi400kb $ sudo ./a.out 
time1625182167.740621	x 432	y 974
time1625182167.740621	x 432	y 975
time1625182167.756625	x 431	y 975
time1625182167.788591	x 430	y 975
time1625182168.636740	x 423	y 975
time1625182168.652710	x 418	y 975
time1625182168.668749	x 417	y 975
Mouse button pressed!!
Mouse button released!!

Has somebody already implemented "pi400ms" to make Pi400 act as mouse in gadget mode, like "pi400kb" from Gadgetoid for keyboard?


P.S:
Linux event handling for keyboards/mice/trackballs/touchscreens/... is described here:
https://www.kernel.org/doc/html/v4.15/i ... codes.html
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Fri Jul 02, 2021 9:09 am

Not needed for pi400ms, but nice -- the uinput example where C code injects mouse move events [50x relative by (+5,+5)], from here (just some #include's needed to be added):
https://www.kernel.org/doc/html/v4.15/i ... -movements

Code: Select all

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <linux/uinput.h>

/* emit function is identical to of the first example */
void emit(int fd, int type, int code, int val)
{
   struct input_event ie;

   ie.type = type;
   ie.code = code;
   ie.value = val;
   /* timestamp values below are ignored */
   ie.time.tv_sec = 0;
   ie.time.tv_usec = 0;

   write(fd, &ie, sizeof(ie));
}

int main(void)
{
   struct uinput_setup usetup;
   int i = 50;

   int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);

   /* enable mouse button left and relative events */
   ioctl(fd, UI_SET_EVBIT, EV_KEY);
   ioctl(fd, UI_SET_KEYBIT, BTN_LEFT);

   ioctl(fd, UI_SET_EVBIT, EV_REL);
   ioctl(fd, UI_SET_RELBIT, REL_X);
   ioctl(fd, UI_SET_RELBIT, REL_Y);

   memset(&usetup, 0, sizeof(usetup));
   usetup.id.bustype = BUS_USB;
   usetup.id.vendor = 0x1234; /* sample vendor */
   usetup.id.product = 0x5678; /* sample product */
   strcpy(usetup.name, "Example device");

   ioctl(fd, UI_DEV_SETUP, &usetup);
   ioctl(fd, UI_DEV_CREATE);

   /*
    * On UI_DEV_CREATE the kernel will create the device node for this
    * device. We are inserting a pause here so that userspace has time
    * to detect, initialize the new device, and can start listening to
    * the event, otherwise it will not notice the event we are about
    * to send. This pause is only needed in our example code!
    */
   sleep(1);

   /* Move the mouse diagonally, 5 units per axis */
   while (i--) {
      emit(fd, EV_REL, REL_X, 5);
      emit(fd, EV_REL, REL_Y, 5);
      emit(fd, EV_SYN, SYN_REPORT, 0);
      usleep(15000);
   }

   /*
    * Give userspace some time to read the events before we destroy the
    * device with UI_DEV_DESTOY.
    */
   sleep(1);

   ioctl(fd, UI_DEV_DESTROY);
   close(fd);

   return 0;
}
Peek_2021-07-02_11-05.gif
Peek_2021-07-02_11-05.gif
Peek_2021-07-02_11-05.gif (24.11 KiB) Viewed 1933 times
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Fri Jul 02, 2021 12:26 pm

I completely rewrote ms_pos.c code from previous posting.
Here is "mstr_events.c" gist that helps to analyze all mouse/trackball related events (no X11 needed):
https://gist.github.com/Hermann-SW/3d7a ... 0e130c20db

I have added examples for all events in 1st comment of the gist.

All events work for mouse as well as trackball, this is the only event that is available on trackball only (move wheel left/right):

Code: Select all

...
time1625227496.693346	type 2	code 6	value 1
rel wheel	right
time1625227496.693346	type 0	code 0	value 0
syn report
time1625227497.959491	type 2	code 6	value -1
rel wheel	left
time1625227497.959491	type 0	code 0	value 0
syn report
...
Because this is event analysis tool, always event type+code+value are printed with timestamp.

The only tricky part is processing vertical/horizontal wheel events, because they consist of two events and 2nd event is read separately from main while loop, see here for vertical wheel move:
https://gist.github.com/Hermann-SW/3d7a ... ents-c-L44

So the mouse/trackball input seems to be fine for "pi400ms", only gadget side is missing yet.
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Fri Jul 02, 2021 11:58 pm

Making progress on mouse event side.
Record and replay already works, with netcat client on Pi400 and netcat server on laptop mouse events should act on laptop as needed, without adding the gadget stuff first.
This is "ms.c":

Code: Select all

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <linux/uinput.h>
#include <assert.h>

int main(void)
{
   struct uinput_setup usetup;

   int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);

   ioctl(fd, UI_SET_EVBIT, EV_KEY);
   ioctl(fd, UI_SET_KEYBIT, BTN_LEFT);

   ioctl(fd, UI_SET_EVBIT, EV_REL);
   ioctl(fd, UI_SET_RELBIT, REL_X);
   ioctl(fd, UI_SET_RELBIT, REL_Y);

   memset(&usetup, 0, sizeof(usetup));
   usetup.id.bustype = BUS_USB;
   usetup.id.vendor = 0x1234; /* sample vendor */
   usetup.id.product = 0x5678; /* sample product */
   strcpy(usetup.name, "mouse replay");

   ioctl(fd, UI_DEV_SETUP, &usetup);
   ioctl(fd, UI_DEV_CREATE);

   sleep(1);

   char buf[16];
   while (!feof(stdin))
   {
     if (fread(buf, 16, 1, stdin) == 0)
       break;
     assert(write(fd, buf, 16) == 16);
     usleep(15000);
   }

   sleep(1);

   ioctl(fd, UI_DEV_DESTROY);
   close(fd);

   return 0;
}

Recording mouse events is as easy as copying /dev/input/event0 into a file.
"ms.c" then can replay the recording:
Peek_2021-07-03_01-53.gif
Peek_2021-07-03_01-53.gif
Peek_2021-07-03_01-53.gif (49.4 KiB) Viewed 1869 times
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Sat Jul 03, 2021 3:04 pm

I tried to replay captured mouse event sequence on Intel laptop with RHEL Linux.
It did not work.

Then I captured trackball events like I did yesterday on Pi400:

Code: Select all

$ sudo cat /dev/input/event6 > y
^C
$
Replaying that capture with ms.c did not work either.

Then I looked into the Pi400 capture start, here "struct input_event" is of size 16 bytes (the first 8 bytes are timestamp, followed by 2 bytes each for type and code, and 4 bytes for value:

Code: Select all

$ od -tx1 x | head -4
0000000 e4 a6 df 60 32 ca 0a 00 02 00 00 00 ff ff ff ff
0000020 e4 a6 df 60 32 ca 0a 00 02 00 01 00 ff ff ff ff
0000040 e4 a6 df 60 32 ca 0a 00 00 00 00 00 00 00 00 00
0000060 e4 a6 df 60 90 08 0b 00 02 00 00 00 fb ff ff ff
$

The events captured on Intel laptop have 24 bytes size of struct input:

Code: Select all

$ od -tx1 y | head -4
0000000 13 78 e0 60 00 00 00 00 cb 13 00 00 00 00 00 00
0000020 02 00 00 00 ff ff ff ff 13 78 e0 60 00 00 00 00
0000040 cb 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0000060 13 78 e0 60 00 00 00 00 23 2a 00 00 00 00 00 00
$ 

After I did change ms.c on Intel laptop to deal with 24 bytes ...

Code: Select all

$ diff ms.c.orig ms.c
32c32
<    char buf[16];
---
>    char buf[24];
35c35
<      if (fread(buf, 16, 1, stdin) == 0)
---
>      if (fread(buf, 24, 1, stdin) == 0)
37c37
<      assert(write(fd, buf, 16) == 16);
---
>      assert(write(fd, buf, 24) == 24);
$ 
... the replay of trackball events captured on Intel laptop immediately worked!

So some software layer has to reformat struct input_event between Pi400 and Intel laptop, up to that replaying Pi400 mouse events on Intel laptop will just work.
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Sat Jul 03, 2021 5:55 pm

HermannSW wrote:
Sat Jul 03, 2021 3:04 pm
So some software layer has to reformat struct input_event between Pi400 and Intel laptop, up to that replaying Pi400 mouse events on Intel laptop will just work.
DONE!

Not with the gadget work, but with making Raspberry mouse as well as trackball, both connected to Pi400, work for laptop!
I even tested the trackball wheel left/right move functionality on a wide webpage:
Moving trackball wheel right moves the displayed page more and more to the left, moving wheel left moves page to the right.

I created gist mstr.c, that works together with Pi400 as laptop keyboard gadget:
https://gist.github.com/Hermann-SW/a378 ... 270bc56e31

I had to add quite some ioctls to ms.c in order to make all mouse+trackball features working:

Code: Select all

   ioctl(fd, UI_SET_EVBIT, EV_KEY);
   ioctl(fd, UI_SET_KEYBIT, BTN_LEFT);
   ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE);
   ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT);

   ioctl(fd, UI_SET_EVBIT, EV_REL);
   ioctl(fd, UI_SET_RELBIT, REL_X);
   ioctl(fd, UI_SET_RELBIT, REL_Y);
   ioctl(fd, UI_SET_RELBIT, REL_WHEEL);
   ioctl(fd, UI_SET_RELBIT, REL_HWHEEL);

This is the main copy and correctly deal with different "struct input_event" size loop:

Code: Select all

   const int pi_ie_sz = 16;
   const int ie_sz = sizeof(struct input_event);
   char buf[ie_sz];
   void *q = buf + ie_sz - pi_ie_sz;
   while (!feof(stdin))
   {
     if (fread(q, pi_ie_sz, 1, stdin) == 0)  break;
     bzero(buf, ie_sz - 8);
     assert(write(fd, buf, ie_sz) == ie_sz);
     if (!nodelay)  usleep(15000);
   }
The "-nodelay" option was important, if not replaying recorded event files any delay is bad.
The bzero() in while loop does zero all timestamps (RHEL has long sec and usec,16 bytes -- Pi400 has only 8 bytes).


This is how it works, on Pi400 open terminal and start netcat service listening on port 8888 and pushing received events reformatted into /dev/uinput:

Code: Select all

$ nc -l 8888 | sudo ./mstr -nodelay

After that is started, switch short back to Pi400 and create terminal with this command capturing mouse and trackball events and sending those to netcat service on laptop:

Code: Select all

( cat /dev/input/event0 & cat /dev/input/event3 & wait ) | nc laptopip 8888

Finally switch display back to laptop and work with Raspberry mouse and/or trackball (whatever you like) on the laptop.

I did create the gist as well as write this posting with browser on laptop, Pi400 keyboard, and I happily switched using Raspberry mouse and trackball the whole time -- just works!


Summay:
mouse and/or trackball events from Pi400 are transmitted over netcat session to laptop and are replayed there, so that both work for the laptop.
Drawback is that network connectivity is needed (before I did turn networking off before running "laptop" alias, because of Pi400 gadget mode keyboard works for latptop without network).

Next step (I don't know when, have too many other open projects, will switch to raspcatbot work now), is to either extend pi400 gadget keyboard to transmit both, keyboard as well as mouse/trackball events, and if that is not possible, create a separate pi400mstr gadget that can be run in parallel to pi400kb gadget.

20210703_200259.15%.jpg
20210703_200259.15%.jpg
20210703_200259.15%.jpg (57.32 KiB) Viewed 1760 times

P.S:
pi400 keyboard gadget is a bit dangerous -- if pi400kb is running, then pressing "Fn+F10" does not power off the Pi400, but the laptop instead -- this now happened the 2nd time to me.
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

epicatsup
Posts: 7
Joined: Sun Dec 13, 2020 10:36 pm

Re: Use Pi 400 as Pi Keyboard

Sun Aug 01, 2021 11:43 pm

where do we put the main.c file

bhattjaidev
Posts: 2
Joined: Mon Aug 09, 2021 6:17 pm

Re: Use Pi 400 as Pi Keyboard

Sat Aug 14, 2021 12:14 pm

cleverca22 wrote:
Wed Dec 16, 2020 10:13 am
cleverca22 wrote:
Sun Nov 29, 2020 12:47 pm
https://hydra.angeldsis.com/build/10480 ... 1/root.zip
https://github.com/librerpi/rpi-tools/b ... oxy/main.c

and this is what happens when people dont stop me, lol

unpack root.zip to a fat32 formatted uSD card, pop it into a pi400, and then plug the usb-c port into any computer with a normal C->A cable

after ~5 seconds, it will function like a normal usb keyboard!
https://hydra.angeldsis.com/build/104811 has a slightly more recent build of it


it has some bugs involving holding multiple keys at once, but ctrl/alt/shift are all fine to be held, so its enough to do basic tasks, but it wont handle gaming well (things like holding w and mashing a/d for ex)

https://twitter.com/Gadgetoid/status/13 ... 9497621505
and this guy beat me to it by about a week, but i suspect my setup process is simpler, i need to review his code and see if i can just bundle it into my root.zip to fix the rollover bugs
Unable to get this working, have added it on formatted uSD, also tried different uSD card, no luck!
Could there be a video/gif which could be referred to get the rpi400 working as a keyboard?

User avatar
HermannSW
Posts: 4544
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Use Pi 400 as Pi Keyboard

Sun Aug 15, 2021 11:54 am

Gadgetoid's repo cannot be built, but you can use his prebuilt executable, if you trust it.

In this previous posting I stated that I forked his repo and changed stuff needed to build yourself, with updated README.md:
viewtopic.php?f=140&t=295074&p=1901693#p1884232
With that you can look into source and see that the typed characters only get send to the connected laptop and are not "phoned home" to anywhere else -- that was enough for me to trust the self made "pi400". Just fullow the instructions in README.md of my fork:
https://gist.github.com/Hermann-SW/19c7 ... i400-c-L85
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

cleverca22
Posts: 4425
Joined: Sat Aug 18, 2012 2:33 pm

Re: Use Pi 400 as Pi Keyboard

Sun Aug 15, 2021 11:01 pm

bhattjaidev wrote:
Sat Aug 14, 2021 12:14 pm
Unable to get this working, have added it on formatted uSD, also tried different uSD card, no luck!
Could there be a video/gif which could be referred to get the rpi400 working as a keyboard?
how did you format the uSD card? what does `fdisk -l` report for it? are the files in the root of the fat32 partition?

i should probably look into pre-building a disk image as well, to simplify all of that

bhattjaidev
Posts: 2
Joined: Mon Aug 09, 2021 6:17 pm

Re: Use Pi 400 as Pi Keyboard

Mon Aug 16, 2021 3:22 pm

cleverca22 wrote:
Sun Aug 15, 2021 11:01 pm
bhattjaidev wrote:
Sat Aug 14, 2021 12:14 pm
Unable to get this working, have added it on formatted uSD, also tried different uSD card, no luck!
Could there be a video/gif which could be referred to get the rpi400 working as a keyboard?
how did you format the uSD card? what does `fdisk -l` report for it? are the files in the root of the fat32 partition?

i should probably look into pre-building a disk image as well, to simplify all of that
I'd formatted this 1gb card through the raspberry pi Imager itself

Here's the fdisk -l report :
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 1929215 1921024 938M c W95 FAT32 (LBA)

Return to “Raspberry Pi 400”