[WORK-AROUND - call NON-PUBLIC method] Custom game loop (not using Game class) - only partial info from Keyboard.GetState

UPDATE - bizarrely, after switching screens to type my previous reply, WHILE stopped at that “Test()” breakpoint, then returning to Visual Studio, “Continue F5”, the NEXT Keyboard.GetState DOES see the “W”.

This is strange, because when simply running in a loop, the W was never seen.
Somehow, switching screens and back changed something.

Focus problem maybe?

CapsLock is a persistent state, so all apps see it, but the keys themselves got intercepted?
Hmm, that doesn’t seem right, since it is their “Pressed” state that is being detected.

On XNA 3.1, I would see the keys no matter what app had focus - this is a low level input call, right?

Also curious is that the “W” was no longer being held down, so that info was held somewhere.
The second Keyboard.GetState was in later code - no intervening “FrameworkDispatcher.Update”. Logically, this should have seen same (wrong) state as the first call.


UPDATE #2 - FIXED!

Only calling Enable once - works.

VB:

Private Shared _KeyboardIsEnabled As Boolean

' WORK-AROUND: Call NON-PUBLIC method.
Public Sub SetKeyboardInput(enable As Boolean)
    If _KeyboardIsEnabled = enable Then Return

    Dim keyboardType As Type = GetType(Microsoft.Xna.Framework.Input.Keyboard)
    Dim methodInfo As MethodInfo = keyboardType.GetMethod("SetActive", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.[Static])
    methodInfo.Invoke(Nothing, New Object() {enable})
    _KeyboardIsEnabled = enable
End Sub