Jump to content

  • Log In with Google      Sign In   
  • Create Account

C# rumblepad SlimDX reflection

  • You cannot reply to this topic
No replies to this topic

#1 mr_signal   Members   -  Reputation: 102


Posted 29 May 2014 - 06:30 AM

I am trying to create a robot controlled by a joystick.  I am using a Logitech Rumblepad with two POV's and multiple buttons (a gamepad).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SlimDX.DirectInput;
using Rachelbot.API;
using System.Reflection;

namespace Rachelbot.API
public class rumblepad
private Joystick joystick;
private JoystickState state = new JoystickState();

public rumblepad(DirectInput directInput, int number)
// Search for Device
var devices = directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
if (devices.Count == 0 || devices[number] == null)
// No Device

// Create Gamepad
joystick = new Joystick(directInput, devices[number].InstanceGuid);
//joystick.SetCooperativeLevel(game.Window.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);

// Set Axis Range for the Analog Sticks between -1000 and 1000
foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);

public JoystickState GetState()
if (joystick.Acquire().IsFailure || joystick.Poll().IsFailure)
state = new JoystickState();
return state;

state = joystick.GetCurrentState();

return state;



I am using the tick function to check the state of the joystick. All I am returning in the state is info from the 1st POV stick and nothing from the 2nd POV stick or the buttons.  It looks as if the information is in the non-public members for the buttons, but I am unsure of how to use the reflection to read the pressedbuttuns and releasedbuttons.