March 11th, 2010

XInput for .NET

With the release of its new XBox360 console, Microsoft has published a new standard input API for game controllers. Not surprisingly, the only controller which currently conforms to this standard is the 360 controller. The good news here is that this controller uses a USB interface so anyone can make their own version and it will be usable on the XBox360 as well as a computer. This fact, combined with the new XBox Live Marketplace feature on the 360 has the potential to really bridge the gap between a lot of console games and the PC gaming market. Anyway, because it looked cool, I went ahead and picked up a wired 360 controller to play with over winter break. Mind you, I don’t own an XBox360, but it has nevertheless turned out to be a lot of fun to play with.

Much to my dismay, the XInput library is not available via the managed DirectX interface. Now, I’m completely comfortable writing DirectX code in C++, but honestly, if I’m just screwing around with a demo, it really doesn’t make sense to jump through all the hoops of setting up a DirectX enabled project in C++; lets be honest, it really is a mess. On the other hand, the managed code interface is beautiful in it’s simplicity and succinctness but doesn’t pack quite the same performance. In my current project, all the hard work is being done on the GPU via VertexBuffers and vertex/pixel shaders so I figured the small amount of managed code actually being executed wouldn’t make much difference.

In any case, I ended up wrapping up the XInput calls in a managed DLL to use in this project. It only took about 15 min but I figured I should post it anyway, in case anyone else wants to play with it and to serve as a small code sample.

Download the Project

Download the DLL

RSS | Comments RSS | title image copyright Robert Gendler |