Connecting USB Keyboard to both USB Host Shield and PC

I'm doing a project with the USB Host Shield, and I need to connect the keyboard to BOTH the USB Host Shield and to connect the keyboard to the PC so it functions normally. I've tried doing so with a USB Hub (Connected the keyboard to the hub, and from that to the PC and USB Host Shield) but the shield is not recognizing the keyboard. It works only when I connect the keyboard directly. Any tips on how I could connect it to both? (I'm a complete beginner to programming and electronics, so I probably won't understand anything too advanced)

Connect the keyboard to the host shield and copy all received keys onto another USB (keyboard slave) shield connected to the PC.

Thank you for the reply, but could you please elaborate? What do you mean by keyboard slave? I'll have to get a second USB Host Shield?

No. A PC expects external USB slaves only.

I really can't imagine what you mean by "copy all received keys onto another USB (keyboard slave) shield connected to the PC." It's probably a stupid question but I'm a complete beginner. This is the setup which receives the keys from the keyboard and shows them on the serial monitor. I just need the same keyboard to be connected to the pc and function normally

You can not connect a USB slave (keyboard...) to multiple USB masters. And a Serial USB connection can not be used for a HID USB keyboard emulation.

That's why two independent USB buses have to be used, one from keyboard (HID slave) to Arduino (master) and another one from Arduino (HID slave) to PC (master).

If that still is too complicated for you then begin with simpler projects before you attack ambitious USB coding.

I know I don't have the knowledge to do this, but I don't have a choice. It's a project for school and if I don't do it I don't pass, so I have to just somehow manage to do it. I have no other guidance and nowhere else to seek help, since it's a pretty obscure project and I haven't found anything like that on the internet, so I have no other sources. Also, what do you mean by the Arduino HID slave? What kind of a shield do I have to buy?

So you should have learned everything about USB bus and classes at school?
Or is your project based on a PS/2 keyboard?

You need a USB shield that (also) can behave as a USB slave of HID class. I'm not sure whether another USB master shield can do that. Check the examples coming with your USB shield for possible use cases.

If you cannot find such a shield then ask your teacher. I were not surprised if he can not give you a link to such a shield.

One solution might be an Arduino that can emulate a USB keyboard, like the old Leonardo can do. Then you use that interface for the PC communication and connect your USB host shield to your keyboard.

The Arduino Leonardo is a really good suggestion, I could connect the keyboard to the USB Host Shield, Connect the shield to Leonardo, but I checked and The USB Host Shield and Leonardo are unfortunately not compatible.

Not the best choice, there are newer boards with possibly better support. Please check the Arduino store yourself.

but I checked and The USB Host Shield and Leonardo are unfortunately not compatible.

I do not think this is true because there are projects using both boards to make USB device pass throughes. The SparkFun USB host shield is probably not compatible.

For example, the following mentions using Leonardo and USB host shield to make a mouse pass through. The only difference is in software to make a USB keyboard pass through.

Most newer boards using 3.3V logic so are not safe to use with the USB host shield.

can we use the serial communication RX and TX of arduino uno to PC in parallel once we convert the arduino uno to USB HID like keyboard

These pins are tied to the USB communication.

so we required two serial ports, right??

Right