How to send keystrokes from one computer to another by USB? - keyboard

Is there a way to use one computer to send keystrokes to another by usb ?
What i'm looking to do is to capture the usb signal used by a keyboard (with USBTrace for example) and use it with PC-1 to send it to PC-2.
So that PC-2 reconize it as a regular keyboard input.
Some leads to do this would be very appreciated.

What you essentially need is a USB port on PC-1 that will act as a USB device for PC-2.
That is not possible for the vast majority of PC systems because USB is an asymmetric bus, with a host/device (or master/slave, if you wish) architecture. USB controllers (and their ports) on most PCs can only work in host mode and cannot simulate a device.
That is the reason that you cannot network computers through USB without a special cable with specialised electronics.
The only exception is if you somehow have a PC that supports the USB On-The-Go standard that allows for a USB port to act in both host and device mode. USB-OTG devices do exist, but they are usually embedded devices (smartphones etc). I don't know if there is a way to add a USB-OTG port to a commodity PC.
EDIT:
If you do not need a keyboard before the OS on PC-2 boots, you might be able to use a pair of USB Bluetooth dongles - one on each PC. You'd have to use specialised software on PC-1, but it is definitely possible - I've already seen a possible implementation on Linux, and I am reasonably certain that there must be one for Windows. You will also need Bluetooth HID drivers on PC-2, if they are not already installed.
On a different note, have you considered a purely software/network solution such as TightVNC?

There is a solution:
https://github.com/Flowm/etherkey
This uses a network connection from your computer to the raspi which is connected to a teensy (usb developer board) to send the key strokes.
This solution is not an out-of-the-box product. The required skill is similar to programming some other devices like arduino. But it's a complete and working setup.

The cheapest options are commercial microcontrollers (eg arduino platform, pic, etc) or ready built usb keyboard controllers (eg i-pac, arcade controllers,etc)

SEARCH THIS PROGRAM:
TWedge: Keyboard Wedge Software (RS232, Serial, TCP, Bluetooth)
then, MAKE YOUR OWN CONNECTION CABLE WITH:
(usb <-> rs232) + (NULL MODEM) + (rs232 <-> usb)
Connect 2 computer, write your own program to send signal to your (usb <-> rs232) unit, then you can control another computer under the help of TWedge.

The above mentionned https://github.com/Flowm/etherkey is one way. The keyboard is emulated from an rPi, but the principle can be used from PC to PC (or Mac to Whatever). The core answer to your question is to use an OTG-capable chip, and then you control this chip via a USB-serial adapter.
https://euer.krebsco.de/a-software-kvm-switch.html
uses a very similar method, using an Arduino instead of the Teensy.
The generic answer is: you need an OTG capable, or slave capable device: Arduino, Teensy, Pi 0 (either from Rapberry or Orange brands, both work; only the ZERO models are OTG capable), or, an rPi-A with heavy customisation (since it does not include USB hub, it can theoretically be converted into a slave; never found any public tutorial to do it), or any smartphone (Samsung, Nokia, HTC, Oukitel ... most smartphones are OTG capable). If you go for a Pi or a phone, then, you want to dig around USB Gadget. Cheaper solutions (Arduino/Teensy) need custom firmware.

Related

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?)
Have a host machine A and a target machine B.
Connect A and B with a USB 3.0 Type-A male-male cable.
The USB connection shows up as an HID keyboard device on B.
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)
It shouldn't require any program installed on B.
What I already searched:
USB 3.0 Host to host connection is possible:
https://superuser.com/questions/795053/how-do-i-connect-two-computers-using-usb-3-0
USB 2.0 Host to host connection is impossible:
https://superuser.com/questions/99274/how-to-connect-two-computers-with-usb
Similar questions asked without the assumption that USB 3.0 Host to Host connection is possible:
https://superuser.com/questions/1128365/simulate-usb-keyboard-from-machine
Setting up a computer to act as an HID device connected to another computer via ps/2,usb or another wired connection
https://superuser.com/questions/507921/computer-to-act-as-keyboard?rq=1
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!

Use a Linux Computer as a USB Coupler

I am on debian and:
I have a USB controller hooked up to a USB port on my PC (Device 1).
I have a male to male USB cord hooked up to another port on the PC that connects to Device 2. (it is a "bridging" usb cord, and has the chip for it)
I want to make them connect to each other as if they were one cord, so neither device knows that there is a computer in the middle.
This would be called a 'Coupler', except that I am using a PC as a coupler.
Here is a (really bad) diagram I made:
What I have done:
I have been able to connect the two devices independently of each other and sniff the results for when they fail to connect. The devices don't send a large volume of data back and forth.
Maybe there is some kind of command tool that I could use, for example (psudocode):
$ couple-usb-ports PORT1 PORT2
You're trying to reinvent the wheel here.
You might consider looking at this link instead.
http://dan3lmi.blogspot.com/2012/10/sniffing-usb-traffic-different.html
Specifically this.
Windows: You cannot directly capture raw USB traffic on Windows with Wireshark/WinPcap, but it is possible to capture and debug USB traffic on a virtual Windows machine under Oracle Virtual Box.
You cannot use a simple PC as transparent USB sniffer without extra (expensive) hardware. An USB bus has always one host (and one or more devices), and the PC can only be the host. This is a hardware limitation.
But you can capture USB data in a Windows machine using Wireshark and USBPcap, eliminating the need for the middle box in most cases.
As this post is tagged Linux, I suppose the controller PC is a Linux machine. Instead of connecting USB ports with a male-male connector, which is all kinds of bad (you are connecting the 5V lines of both machine with each other!), just run Wireshark in the controller PC.
There might be a little work to be done previously, as you have to enable Wireshark for USB monitoring (Particularly in Debian, this is disabled by default), and you might have to install a small driver to enable the monitoring. Have a look at this page for more information.
Once you get it working, Wireshark is an excellent tool for this!

Emulate a Bluetooth Device from PC

I wonder whether it is possible to emulate a specific bluetooth device like a Remote Controller for a TV or another device with my PC. I'd be okay with installing an additional hardware device for my computer (e. g. a BlueTooth PCIe card).
I imagined something like "recording" all single commands of my original remote controller using my Bluetooth card and afterwards use these recorded commands to turn on my TV for example.
Is something like this possible (with additional hardware maybe)?
Of course this is possible. Bluetooth is just a protocol and you can impliment it in your custom software to emulate all kinds of devices. If you need to emulate simple devices like keyboard or mouse, there are many ready solutions like this.
But if you have non standard device, there won't be any ready solutions and you will have to implement it yourself. What can help you:
If you have some kind of controller for PC and you want to emulate device with unknown protocol, you can use WireShark or other sniffer to understand what's going on.
There is an emulator called BT-Sim, but it is so poorly documented that I can't even guess what it does.
You can can take as example different android software like described in answers to this question.
You can check different program samples for PC like this.
For hardware you need only simple Bluetooth dongle. However, if you want to spy on some BLE (Bluetooth Low Energy) devices, you can buy hardware sniffer like this.
(At least in Windows 10) Microsoft Store has an application called "Bluetooth LE Explorer" which is able to simulate different kind of Bluetooth GATT profiles as a peripheral.

Redirect data traffic from and to USB devices on Mac OS/Unix/Linux

I'd like to redirect traffic from and to USB devices in an application.
Particularly I want to talk to USB dongles.
So for example if a dongle is connected on a USB port, is it possible to get the traffic that is intended to be written to this device? On the other hand, can you simply write data in the same manner?
I don't have any experience so I'd appreciate to get some directions.
BTW, this is not intended to be used in anything illegal ;-)
With "USB dongles" you mean: Software license dongles?
First of all you should know that USB is not a stream of data such as RS232 but a very complex bus transferring a lot of different control and data messages.
On Linux you can use Wireshark to monitor the data on the USB bus. There are similar tools for Windows (up to Windows XP only) but the Windows version of Wireshark does only support Ethernet and not USB. Windows 7 has a built-in command line tool that does the same job.
If you really want to redirect data you might use something like "usbip" that allows sharing USB ports over network. You may simulate an USB dongle device by programming a server that simulates the dongle... However doing this is very tricky and requires a lot of programming experience!

Simulating a keyboard's output (making a computer pose as another computer's keyboard)

I want to be able to connect a computer A's USB port to computer B's USB port so as to make computer A act as computer B's keyboard.
Any idea how I would go about doing that?
I'm not looking for a ready-made solution (though if one already exists and is open-sources I
would not object), but for a starting point or a good resource.
I imagine I'd need to write a driver that simulates the keyboard's protocol, and I would also need to sort out the entire USB master/slave scenario.
Anyway, any help would be appreciated.
P.S.
I want to do it with the mouse as well, but I imagine it will be a very similar process, and I think (but I might be wildly mistaken) that starting with the keyboard will be easier.
I am really excited to have found something that will do this from Hagstrom Electronics. It take a serial input and sends a USB keyboard output to another PC. If you combine this with a readily available USB to serial adaptor, then you are golden.
http://www.hagstromelectronics.com/products/usbkm232.html
I have been searching for weeks to find this, so I decided to go back to some forums and share the discovery.
Linux has support for USB gadget mode, but I think you need special hardware for that. I.e. the USB port in a normal PC can not do gadget mode.
An alternative is to wire an LPT port to a PS/2 keyboard input, this is technically simpler.
If it wasn't for the USB, I'd connect the two via LAN and have a client/server C# program that emulates a keyboard / mouse (e.g. via DirectInput).
For the USB part as far as I can tell you'll need some hardware adapter. If you're into hardware development or at least unafraid of a soldering iron and some µc programming, have a look at http://www.obdev.at/products/vusb/hidkeys.html where a HID stack for a small atmel chip is available for free. For this solution you'd need two atmega chips which communicate via I²C or SPI or such.
I'd recommend electrical separation of the two pcs, too. You never know if they share the same electrical ground or not.

Resources