简体   繁体   中英

Using python to simulate USB keyboard

I'm well aware of different automation libraries that I can use in conjunction with Python (or even as a separate program/entity all together)-- that's not what I need here...

Here's what I'd like to accomplish...

{COMP1}  -------->  {COMP2}

(1) --> = COMP1 USB port[01] is connected to COMP2 USB port[01]
    (it could be any port, I'm just using [01] as an example)
(2) COMP1 USB port[01] "looks-like" a Generic USB keyboard
    (I'll maybe need to spoof HID values so COMP2 treats it as a keyboard)
(3) My program would send keystroke signals into COMP2 in such a way that
    COMP2 would treat the input as any other connected keyboard device

I've looked a little bit into pyusb but I think it looks like that's taking control of the connected device, it's not emulating/simulating a device. If I have that wrong, please point me to the right documentation so I understand how to issue signals as if I were a keyboard through the USB port

I think this article begins to really scratch the surface but I have no clue what to do next with it.

Perhaps PySerial might be another method but I haven't found any solid examples where python is issuing keystrokes to the USB (it seems to be listening instead)

Any help or ideas are greatly appreciated!

I ended up using a Teensy 3.2 device instead of coding with python Here's where you can research/purchase it https://www.pjrc.com/teensy/

Basically, this arduino-cousin hardware can masquerade/imitate any USB device (sending a certain HID number)...Once connected to another computer (and a tiny bit of coding), you can send a sequence of keystrokes/commands programmatically to the target computer-- it was very easy (sure soldering for the first time felt a bit mad scientist ) but it was really fun too.

I'll post up the code samples on github if anyone is curious or responds to this thread in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM