1

I've looked around, does anyone know if KeyboardState.GetPressedKeys() (in Microsoft.Xna.Framework.Input) returns the keys in an organised collection (most recent first or last in the list) or some disorganised unpredictable list?

Ghost4Man
  • 1,040
  • 1
  • 12
  • 19

1 Answers1

3

The order of the array is defined by platform's keycode code order.

You cannot determine pressed order using this, or any other MonoGame method, since the system is only queried for currently pressed keycodes, every game loop iteration.

At the default frame rate of 60 fps for Windows games, this equates to 16 milliseconds, the order of key presses becomes somewhat irrelevant. Attempting to make sense of the mashing of keys is nonsensical, unless the goal is to find which key is first pressed (as a "Jeopardy" style button). If that is the case, a hook into the OS will provide the best resolution (up to 240 samples per second on Windows).

The order is always consistent within a platform and keyboard layout. Please see the definition for KeyboardState.cs and Keyboard.Windows.cs.

Ghost4Man
  • 1,040
  • 1
  • 12
  • 19