Hykilpikonna
Hykilpikonna

Reputation: 2161

Can a USB 3 Host machine be programmed as a USB 3 Peripheral (or a HID keyboard)?

What I want to do:

An AI program on a host machine, reading inputs from a camera sensing the screen of the target machine and outputting controls to the target machine via USB connection--programming the host machine's USB host as a USB peripheral connected to the target machine.

What I want to do step by step: (is it possible to implement the steps below?)

  1. Have a host machine A and a target machine B.
  2. Connect A and B with a USB 3.0 Type-A male-male cable.
  3. The USB connection shows up as an HID keyboard device on B.
  4. Write code to simulate key presses on A that sends to B.
    (Eg. calling press('F') on a program running on A would type F to B's input)
  5. It shouldn't require any program installed on B.

What I already searched:

  1. USB 3.0 Host to host connection is possible: https://superuser.com/questions/795053/how-do-i-connect-two-computers-using-usb-3-0

  2. USB 2.0 Host to host connection is impossible: https://superuser.com/questions/99274/how-to-connect-two-computers-with-usb

  3. Similar questions asked without the assumption that USB 3.0 Host to Host connection is possible:

Upvotes: 1

Views: 492

Answers (1)

markus-nm
markus-nm

Reputation: 865

Suggestions in ascending order of feasibility:

USB Gadgets

You are using linux, so the default way would be to create/configure/load a gadget driver. Have a look at this tutorial, though for a raspberry, should work on your PC too. However, I could not find any information regarding the use of USB3 - the tutorial assumes your host is using one of it's OTG ports, which your PC most likely does not have. So whether this works with your USB3.1 Type-A-to-Type-A connection you'll need to test.

USBIP

The idea of sharing USB devices (not just keyboards) is not really new. With USBIP you can "export" any local USB device to the network, and your client will need the client-side USBIP driver to access the keyboard.

Dont bother with USB at all, just use Ethernet

I'd simply write two userland scripts/programs that send/receive+execute the keystrokes. Very easy to implement, you're probably familiar with python anyway.


If you absolutely cant have software installed on the client-PC and your Type-C-to-Type-C connection doesnt support USB Gadgets, there's another way. It basically involves the use of two USB-to-serial adapters (~15$) and a serial cable. While this wont be enumerated as a keyboard, but rather as serial port, it's the lowest-effort solution to transfer data without additional software on the client. Both computers will just do file I/O. If your computers still have COM-ports, you can even omit the serial converters!

Upvotes: 1

Related Questions