bayangan1991 / PYXInput

Python Library for Creating and Analysing XInput devices
https://pypi.python.org/pypi/PYXInput
MIT License
87 stars 22 forks source link

Problem with pressing buttons #6

Closed skaftanis closed 6 years ago

skaftanis commented 6 years ago

Hi, thank you for the very good job here!

I'm trying to use this on a racing game. Axis and triggers looks fine, but I have a problem with buttons. I want to use buttons for up shifting and down shifting. So, I want to create a simple example where the agent down shift one gear every second. I use this code

while True:
    MyVirtual.set_value('BtnX', 1.0)
    MyVirtual.set_value('BtnX', -1.0)
    time.sleep(1)

But the car down shift one time, then the control disconnects from the game for some reason and the game go on pause menu.

The disconnect is not the problem thought for example when I steer the car with:

counter = 32768
while True:
    MyVirtual.set_value('AxisLx', counter)
    counter = counter + 1
    if (counter == 32767 ):
        counter = -32768
    time.sleep(1)

it works fine after the pause (I just skip the pause pressing ESC) and then it doesn't disconnect again. So the problem is possibly just with buttons (or just the release of the button, I don't know). Can you help me with that?

bayangan1991 commented 6 years ago

Hey @skaftanis, Thanks for the feedback.

I think the problem is that you are setting a button value to -1.

Buttons take need a Truthy and Falsey value:

try this:

while True:
    MyVirtual.set_value('BtnX', 1)
    time.sleep(0.1)
    MyVirtual.set_value('BtnX', 0)
    time.sleep(1)
skaftanis commented 6 years ago

Thanks! It works fine :)