To handle text input, you need to know when a key is pressed or released. Unfortunately, the XNA KeyboardState doesn't really help with this, so you need to do it yourself. Basically, you just need to compare the current update by pressing the keys with the keys pressed from the previous update.
public class KbHandler { private Keys[] lastPressedKeys; public KbHandler() { lastPressedKeys = new Keys[0]; } public void Update() { KeyboardState kbState = Keyboard.GetState(); Keys[] pressedKeys = kbState.GetPressedKeys();
Give the game class KbHandler and name it "Update Method" from your game update method.
(By the way, perhaps a more efficient way to compare two arrays than with foreach and Contains, but with so many elements to compare, I doubt it will matter.)
source share