How Can I Call GetAsyncKeyState() in UWP DirectX/XAML App?

蓝咒 提交于 2019-12-25 08:59:35

问题


I have some code I'm porting from a working WinJS/UWP app to a DirectX/XAML variant, but I can't get my hands on the keyboard state.

Controller is not a problem, that works just fine via XInputGetState(). My problem is just the keyboard.

Existing code is:

Windows::UI::Core::CoreWindow^ win =
    Windows::UI::Core::CoreWindow::GetForCurrentThread();      
if (win)
{   
    // misc. calls to win->GetAsyncKeyState()
}
XInputGetState(activeController, &inputState);

But that fails because Windows::UI::Core::CoreWindow::GetForCurrentThread() returns null.

If I try this, I can get a win object:

Windows::UI::Core::CoreWindow^ win =
    Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow;

if (win)
{   
    // misc. calls to win->GetAsyncKeyState()
}
XInputGetState(activeController, &inputState);

But then the window (a swapChainPanel) doesn't render.

In fact if I take out the 'if' part altogether on that one, it still doesn't render as though the action of me having the termerity to get a reference to the CoreWindow means it goes off in a huff.

I'd kind of like to have keyboard input, controller input and graphics output at the same time.

Can anyone help me with the correct incantation that gets me a CoreWindow I can use without important other features stopping working?

This is all C++. And it's code that works in WinJS.

来源:https://stackoverflow.com/questions/45103819/how-can-i-call-getasynckeystate-in-uwp-directx-xaml-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!