Host shield output to emulate keyboard

I would like to create project that can write/typing keyboard to PC B from my PC A with arduino real time.

The photo below shows an Arduino Leonardo + USB Host Shield. Can you create an Arduino project to emulate a keyboard?

  • The white micro USB cable is connected to Computer A to run the script.
  • The blue USB cable is connected to Computer B to emulate a keyboard (similar to a physical keyboard).

So, every time Computer A runs a script, for example, typing "Hello," Computer B should also type "Hello." I've tried several tutorials, but the output still goes to Computer A via the white cable, and the blue cable on the compyter B doesn't detect anything. Thank you.

code

#include <Keyboard.h>
int ledPin = 13;

void setup() {
  Serial.begin(9600);
  Keyboard.begin();
  pinMode(ledPin, OUTPUT);
}


void loop() {
  if (Serial.available() > 0) {
    char command = Serial.read();
    if (command == '1') {
      digitalWrite(ledPin, HIGH); // Turn on the LED

      Keyboard.press('e');
      delay(250); 
      Keyboard.release('e');
    } else if (command == '0') {
      digitalWrite(ledPin, LOW);  // Turn off the LED
    }
  }

  // Wait for 5 seconds
  delay(5000);
}

I think you'd better share your code.

Welcome to the forum

What sketch is running on the Arduino ?

updated with code

First of all, I just wanna know is that possible to make usb hostshield as Host output and act like a keyboard?

updated with my code

Which Arduino board are you using ?

already mention in my post, Arduino leonardo and usb host shield, is this detail not enough?

My apologies, I missed that

The Leo can certainly be used to emulate a keyboard. Does it do that OK with the shield disconnected ?

Hi, yes, Leo can emulate and run my script, but I want to use that usb port from leo to connect and run script from my PC A, so I need another usb port to send and emulate keyboard to PC B, thats why I use usb host shield, but it didnt work (not detected on PC B)

Years ago I made an 'Arduino messenger'. Two people could chat through the serial monitor of the Arduino IDE. I used two ARduinos on two sides. I configured two Bluetooth modules in Master-slave mode. I connected them with each of the Arduino. Will this solution solve your purpose?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.