
This Christmas a friend gave me a Xbox wired controller. I don’t have a Xbox 360, but I wanted to try XNA development and use the controller to develop some different user-interfaces on windows-based applications. This weekend I managed to put the first pieces to work
Based on XNA framework which has support for Xbox 360 controller I built an component that you can drag and drop into your windows forms application. You can assign each control instance to a different controller (up to 4) and set the interval between hardware changes checking (the default is 100 miliseconds). This component raises events when the controller status changes. It has a general onChange event, and an event for each button, trigger and stick status change. It has also a method to control the controller vibration.
This component is not a big deal. When it is instantiated, the component creates a new thread which waits for a period of time before returning into the main thread. When it returns it checks for controller changes using the Microsoft.Xna.Framework.Input.GamePad class. This check is made by comparing the current GamePadState with the previous one. For each change it is raised an event to which you can subscribe in your windows application. I tried to use it in a WPF application. It worked, but I had to create the component in code. It didn’t appear in the toolbox.
You can download the component source code and an example here. I added some comments into the code, but I think that it is pretty simple to understand even to people with little experience with C#. Any question/suggestion feel free to comment!
I’ve tried it in a virtual machine in order to find out the software requirements. I had to install XNA Game Studio 2.0 to put it to work… The XNA redistributable wasn’t enough. If someone can tell me how to distribute my examples with minimum software requirements I’ll be glad to hear from you
This is also a great change for you to try Visual Studio 2008, since the solution in the zip package has to be opened in VS2008. If you don’t have access to this software, or you’re having trouble migrating the code into a VS2005 environment just tell me, and I will help you out.
As soon as I develop some applications using Xbox controller I’ll publish them here in my blog.





