Petezah Petezah - 2 months ago 38
C# Question

Using the Xbox 360 Controller in a WPF application

I'm currently trying to use my Xbox 360 controller in my WPF application but all the tutorials online refer to using XNA in a game environment. I was just wondering if there is an easy to get my application to detect my Xbox 360 controller and any movement/button pushes that may come from it. My current setup is visual studio 2010, .NET 4.0, WPf, C#, and I have the xbox 360 wireless adapter for the PC. Thanks!

Answer

Consider [Bruno Silva's solution for integrating the Xbox 360 gamepad with PowerPoint][x]. The first project was for an Office Add-in for Powerpoint, but the base project is a wrapper to allow the gamepad to be used within a Windows or WPF application.

It wraps XNA Microsoft.Xna.Framework.Input.GamePad class and provides an interface with events associated with each button status change, as well as on game pad connect/disconnect.

[Bruno Silva's blog has links to the project and sample code][x].

You'll need to have XNA Framework 2.0 installed. I'm unsure if higher/recent versions are compatible.