none
CoreWindow.GetAsyncKeyState slow

    Pregunta

  • I'm porting a DirectX C++ app to Metro that is sort of like a game demo.  I use the ASWD keys to move the player and the mouse to look like a typical first person shooter.  In my Win32 application I used the free function GetAsyncKeyState.  For Metro, I found the (potential) equivalent CoreWindow.GetAsyncKeyState.  However, after holding a key down for a second or longer, my program begins to stutter like it is getting slow frame rate.  It only stutters when I am holding a key down after about 1 second.  Looking around with the mouse is no problem so it is not a general performance issue. 

    I also tried CoreWindow.GetKeyState and this does not stutter, but it sometimes does not recognize a key press.  For example, I might press and hold the A key but it does not "see it", and I have to press and hold it again for the system to respond to it. 

    Finally, handling the KeyDown event of CoreWindow is too slow as well. 

    Are there any options instead of CoreWindow.GetAsyncKeyState for fast testing if a key is pressed?  I just need the raw state at an instance in time.

     
    domingo, 29 de abril de 2012 22:23

Todas las respuestas

  • Hello,

    Would you please provide us some same codes to reproduce this issue?

    You can upload your project to
    http://skydrive.live.com/

    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    lunes, 30 de abril de 2012 8:01
  • Hi Nullspace007,

    GetAsyncKeyState or KeyUp/KeyDown should both be fast enough for keyboard input in games. The behavior you describe is not expected.

    I can't reproduce this in my local system. Do you get this behavior with just your app or do you also see it with the D3D Sample apps? The DirectX touch input sample uses GetAsyncKeyState in its MoveLookController, and several of the other DX samples use CoreWindow.KeyUp and KeyDown.

    If it is just your app then when, how, and how often are you calling GetAsyncKeyState and responding to its input? If you debug the app can you determine where it is getting bogged down when it stutters? As Jesse suggests, if you can provide a minimal sample which demonstrates how you are calling this and exhibits the problem then we can take a look at it.

    --Rob

    jueves, 03 de mayo de 2012 2:14
    Propietario
  • Hi nullspace,

    I have the same problem here, after diving in it seems GetKeyState and GetAsyncKeyState are in a very unreliable state right now.
    The stuttering "only" appears on for the Down-flag of the keystate.

    A workaround for now to query if the key is pressed:
    if (window->GetAsyncKeyState (theKey) != Windows::UI::Core::CoreVirtualKeyStates::None)
    {   … its pressed … }

    Works fine for me for now... (querying locked keys like capslock or numlock is a whole different story...)


    ---------------------------------------------- Roman Pfneudl CEO - vertex4 entertainment ltd.

    sábado, 19 de mayo de 2012 11:05