Introduction
Well, this class is pretty much the result of my attempt to write an alternative to the Xpadder application by Jonathan (don't know the last name). But because I decided to use C# to realize the application, I had to find a way to catch the input from the controller and because .NET doesn't provide an interface for that, I had to create my own way.
Requirements
Other than .NET 4.x
Using the Code
Other than usual, I'll provide a quick overview. But the source code should provide more than enough hints and if not, the comment section is below this tip.
Creating a New GamepadState Instance
using System;
using SlimDX;
using SlimDX.XInput;
using SlimDXPlugin.XInput;
namespace MyApplication {
public class MyApplication {
public GamepadState Controller1 = new GamepadState(UserIndex.One);
public GamepadState Controller2 = new GamepadState(UserIndex.Two);
}
}
Binding Events
using System;
using SlimDX;
using SlimDX.XInput;
using SlimDXPlugin.XInput;
namespace MyApplication {
public class MyApplication {
public GamepadState Controller1 = new GamepadState(UserIndex.One);
public GamepadState Controller2 = new GamepadState(UserIndex.Two);
public MyApplication() {
Controller1.ButtonA_Pressed += Player1_ButtonA_Pressed;
Controller1.ButtonA_Released += Player1_ButtonA_Released;
Controller2.ThumbstickLeft_Changed += Player2_ThumbstickLeft_Changed;
}
static void Player1_ButtonA_Pressed(object sender, EventArgs e) {
}
static void Player2_ThumbstickLeft_Changed(object sender, ThumbstickEventArgs e) {
}
}
}
State Update
using System;
using SlimDX;
using SlimDX.XInput;
using SlimDXPlugin.XInput;
namespace MyApplication {
public class MyApplication {
public void Tick() {
Controller1.Update();
Controller2.Update();
}
public void BetterTick() {
if(Controller1.Connected) {
Controller1.Update();
}
}
}
}
That's basically all you need. Everything else explains itself. If not, take a look at the source or post your questions in the comments, I will respond as soon as possible.
Points of Interest
Sure, this is probably not the best solution, but at least it's something and for my own application just the right thing. But I hope Microsoft will implement a better solution within .NET.
History
- Initial release (12/30/2014)
- Swapped 7z for zip, code should be browseable now (12/31/2014)