Xbox 360无线控制器无法通过C ++ / WinRT和Windows.Gaming.Input API在控制台应用程序中工作 [英] Xbox 360 Wireless Controller is not working via C++/WinRT and Windows.Gaming.Input API in console application
问题描述
我尝试使用 Windows .Gaming.Input
API通过 C ++ / WinRT (来自Windows控制台应用程序,并且不能与 Xbox 360无线控制器
一起正常工作(报告为用于Windows的Xbox 360无线接收器(0x045e:0x0000)
)。
I trying to use Windows.Gaming.Input
API via C++/WinRT from Windows Console Application and it is not working as supposed with Xbox 360 Wireless Controller
(reported as Xbox 360 Wireless Receiver for Windows (0x045e:0x0000)
).
我得到了 GamepadAdded
事件,然后尝试通过 gamepad.GetCurrentReading()
读取游戏手柄状态,似乎是 GamepadReading
Xbox 360 Wireless Controller
根本没有填充结构。
I got GamepadAdded
event, then trying to read gamepad state via gamepad.GetCurrentReading()
and seems GamepadReading
struct is not filled at all for Xbox 360 Wireless Controller
.
也我发现MSVS调试控制台上有一些奇怪的错误消息:
Also I found that there is some strange error message on MSVS debug console:
onecoreuap\xbox\devices\api\winrt\pnpdevicewatcher.cpp(500)\Windows.Gaming.Input.dll!00007FFE453AABC7: (caller: 00007FFE453AA367) ReturnHr(1) tid(4e04) 80070006 The handle is invalid.
Xbox One游戏控制器(0x045e:0x02d1)
Xbox One Game Controller (0x045e:0x02d1)
is working fine though.
< img src = https://i.stack.imgur.com/tHC9u.png alt =在此处输入图片描述>
什么是我的代码有误吗?还是Windows中的错误?
What is wrong with my code? Or this is bug in Windows?
代码在这里: https://github.com/DJm00n/cppwinrtgamepad
使用Windows 10 1809,MSVS 2017 15.9.9,cppwinrt v1.0.190211.5,Windows SDK v10.0.17763.0, xusb22.sys
v10.0.17163.1, xboxgip.sys
v10.0.17163.1。
Using Windows 10 1809, MSVS 2017 15.9.9, cppwinrt v1.0.190211.5, Windows SDK v10.0.17763.0, xusb22.sys
v10.0.17163.1, xboxgip.sys
v10.0.17163.1.
PS:我还尝试了
PS: I also tried UWP Simple3DGameXaml
app from https://github.com/microsoft/Windows-universal-samples repo - and both controllers works in it.
推荐答案
这是一个已知问题。显然,这是由焦点处理的方式引起的。因此,Windows.Gaming.Input基本上不适用于控制台应用程序,但适用于具有焦点窗口的Win32或UWP应用程序。
This is a known issue. Apparently this is caused by how focus handling works. Windows.Gaming.Input basically doesn't work for console apps as a result, but does work for Win32 or UWP apps that have a window in focus.
请注意,Xbox One控制器为您工作的一种情况仅是因为两个用户都是管理员,并且-因为您启用了开发人员模式。否则,从控制台应用程序根本无法使用。
Note that the one case where the Xbox One controller worked for you is only because both the user was an admin -and- because you had developer mode enabled. It wouldn't work from a console app at all otherwise.
如果您需要旧版Win32控制台应用程序的游戏控制器支持,则可以应该使用XINPUT。参见此博客文章。
If you need game controller support for a legacy Win32 console app, you should use XINPUT. See this blog post.
这篇关于Xbox 360无线控制器无法通过C ++ / WinRT和Windows.Gaming.Input API在控制台应用程序中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!