0

I've used wireshark and get the usb data packets about the "w" key press and on ,then I wanna send the same data packet to my computer usb, making the computer think that my keyboard really pressed the W key.

My question: Firstly, how can I send the data packet to the PC usb hub? Secondly, what is the structure about the data packet to send ? Should I exclude some bytes or add some bytes ?

my PC platform is win11 ,and the pic is about the w key press and on

1

The libraries I use is pywinusb and pyusb.

I've sniffed the UDP traffic before and replayed it well. I think the usb traffic may be the same, but I'm so naive .:)

I'm fresh on usb protocol, could anyone give me any advice? Thx a lot

vimuth
  • 5,064
  • 33
  • 79
  • 116
noir
  • 1
  • 1

1 Answers1

0

You cannot emulate keyboard hardware without installing some special synthesized device driver.

To emulated HID device (and keyboard is a HID device) you can write and install special driver. Look at this sample code: HID Minidriver Sample (UMDF version 2). You can go this way - make some additional IOCTLs that you emulated device driver handles and send commands from user mode - so device will emulate keyboard key presses by your commands.

You can find example HID report descriptor of a keyboard in the "E.6 Report Descriptor (Keyboard)" chapter of the HID spec document. Packet format is described in "F.5 Keyboard: Using the Keyboard Boot Protocol" chapter of the same document.

PS: You can use SendInput function to send keystrokes to an app, may be this is enough for your case:

INPUT inputs[2] = {};
ZeroMemory(inputs, sizeof(inputs));

inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_W;

inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = VK_W;
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP;

UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
DJm00n
  • 1,083
  • 5
  • 18