1

I'm trying to use an xbox controller in WPF and I seem to have run into a problem.

I was able to grab the input from XNA using a gamepad

Microsoft.Xna.Framework.Input.GamePadState currentState = Microsoft.Xna.Framework.Input.GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);

but I can't figure out how to make WPF trigger the say "KeyPressed" event when something on the controller is pressed.

I tried doing some research but I couldn't find anything too specific or if I do they most of the time aren't answered. I found this below but it doesn't seem to answer how you could actually do this:

Can you program buttons on a gamepad to bind with mouse/keybourd input?

Community
  • 1
  • 1
Timlankey
  • 91
  • 1
  • 5

2 Answers2

3

You will need to look at each of the buttons to see if they were pushed.

if (currentState.Buttons.A == ButtonState.Pressed)
{
    do something
}
Lost in Alabama
  • 1,653
  • 10
  • 16
2

As said in another answer, you can check the state of the gamepad with:

if (currentState.Buttons.A == ButtonState.Pressed)

You can also use

if (currentState.IsButtonDown(Buttons.A))

You may want to create a dictionary of Buttons to Key mappings, but that is up to you.

Once you know how to check the gamepad state, your question reduces to this question. See the accepted answer.

Community
  • 1
  • 1
idlewire
  • 499
  • 1
  • 3
  • 11