coxbox变换 python_使用Python模拟XBox控制器输入

I want my python programm to simulate an XBox controller input.

Both analog thumb sticks and the on/off buttons if possible.

I found topics about simulating Keyboard input with ctypes in python, for example here:

Python simulate keydown

Is it possible to simulate it similar to an "keydown" on a normal keyboard or mouse?

解决方案

In case someone with the same problems will find this thread:

I solved the issue with vJoy, pyVJoy and x360ce.

vJoy provides an SDK and driver to simulate input devices. You can have joysticks, gamepads etc..

PyvJoy allows you to access these drivers and simulate the input inside python.

https://github.com/tidzo/pyvjoy

pyvJoy uses values between 0 and 32767 for the "analog" sticks.

For example, to get the left thumb-stick of an xbox controller in a neutral position you put the XAxis and YAxis in 1/2 of 32767.

So for me having input values between 0 and 1 I multiply them with this values.

In my code it looks kinda like this:

MAX_VJOY = 32767

self.j = pyvjoy.VJoyDevice(1)

def play_function(self,X,Y,Z,XRot):

self.j.data.wAxisX = int(X * self.MAX_VJOY)

self.j.data.wAxisY = int(Y * self.MAX_VJOY)

self.j.data.wAxisZ = int(Z * self.MAX_VJOY)

self.j.data.wAxisXRot = int(XRot * self.MAX_VJOY)

j.update()

You can also update "binary"/"digital" buttons this way, the pyvjoy github page has a few more examples.

Try using this Joystick app for calibration: http://www.planetpointy.co.uk/joystick-test-application/

The final part is using X360CE, what is does is turn the vJoy "DigitalInput" Devide into a XInput device. So the PC/game thinks its an actual Xbox 360 or Xbox One Controller. This last part is only needed for some games that only allow official Xbox controllers, like GTA 5.

You can get X360CE from here: http://www.x360ce.com/

All this combined allows me to play those games through python. I learned that using WASD to train a neural network doesnt work too well because it always acts to extreme because it only allows 1 or 0 for the button presses. With these controls you can get smoother game controls.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值