Search code examples
c++inputuwpdirect3d12

KeyDown latency C++ UWP Windows 10 Direct3D 12 Application


My problem is that on KeyDown, there is almost a second of delay until all the queue of events starts being processed, see the video demo here. Secondly, parallel keys are NOT processed, I can either go W, S or some other, but not both at the same time.

I already tried running Render() async and using ProcessUntiLQuit , changing the way I read input, etc...

I am currently using ProcessAllIfPresent in a classic Run(while not closed) loop

In my IFrameworkView instance application, thwe following is my KeyDown handler:

void OnKeyDown(CoreWindow^ wnd, KeyEventArgs^ args) {
    for(int i = 0; i < g_MainApplication->InputMap().size(); ++i) {
        if(g_MainApplication->InputMap()[i] == args->VirtualKey) {
            g_MainApplication->FlagInput((Application::INPUT_MAP)i);
        }
    }
}

There are only K mapped keys in total, so it runs on constant time. This sets all the flags and pass it to the application, which simply calls the "UpdatePosition" method modifying values directly:

void MyApp::ProcessKeyboard(INPUT_MAP key, double delta) {
    delta *= g_SpeedModifier;
    switch(key) {
    case FORWARD: 
        g_SelectedEntity->Translate(DIRECTION::WORLD_FORWARD, static_cast<float>(delta));
        break;
... // more of the same code here.
}

The application is rendering at 60 FPS.

Thanks for your help.


Solution

  • I just tried

    CoreWindow::GetForCurrentThread()->GetAsyncKeyState(VirtualKey)
    

    ... in a continuous loop. It works great.