问题
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