0

I am trying to capture some keyboard keys in python and trying to emulate a controller input which is connected to the USB port with a wire. I stumbled across hid module and was able to successfully read the report in my code. But when i use gamepad.write(report) it doesn't work as expected and my button doesn't get pressed.

import time
import hid

for device in hid.enumerate():
    print(f"0x{device['vendor_id']:04x}:0x{device['product_id']:04x} {device['product_string']}")

gamepad = hid.device()
gamepad.open(0x09da,0xf613)
gamepad.set_nonblocking(True)

time.sleep(2)

while True:
    # reading the report
    report = gamepad.read(64)
    print(report[:7])
    # changing the index 6 to to 4 (because when triangle button is pressed the index 6 becomes 4)
    report[6] = 4
    print(report[:7])
    gamepad.write(report)
    # time.sleep(0.5)

Ideally what I expect is when the modified report is written to the gamepad it should emulate "triangle button" for my gamepad but it doesn't. I am relatively new to coding so if i missed anything or my approach is wrong correct me thanks.

0 Answers0