WPF 中的 XNA GamePad 输入触发事件

发布于 2024-11-28 10:43:14 字数 545 浏览 0 评论 0原文

我正在尝试在 WPF 中使用 xbox 控制器,但似乎遇到了问题。

我能够使用游戏手柄从 XNA 获取输入

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

,但我不知道如何让 WPF 在按下控制器上的某些内容时触发“KeyPressed”事件。

我尝试做一些研究,但我找不到任何太具体的东西,或者即使我做了,大多数时候也没有得到答复。我在下面找到了这个,但它似乎没有回答你实际上如何做到这一点:

您可以对游戏手柄上的按钮进行编程以与鼠标/键盘输入绑定吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请你别敷衍 2024-12-05 10:43:14

您需要查看每个按钮以查看它们是否被按下。

if (currentState.Buttons.A == ButtonState.Pressed)
{
    do something
}

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

if (currentState.Buttons.A == ButtonState.Pressed)
{
    do something
}
ら栖息 2024-12-05 10:43:14

正如另一个答案中所述,您可以使用以下方法检查游戏手柄的状态:

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

您还可以使用

if (currentState.IsButtonDown(Buttons.A))

您可能想要创建按钮到按键映射的字典,但这取决于您。

一旦您知道如何检查游戏手柄状态,您的问题就会减少为 这个问题。查看已接受的答案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文