For example when you press the two keys which i have marked with a red 1 and then go to another process and press space(2) you will get a "~ ". Keyboard.GetState() only receives the space key.
In my Keyboard class, I stored all keys currently being held down to array of keys if not yet on held list and has some properties that can return all keys in array keys or in string:
Store keys being held down to __Lastkeys if not yet on list.
E.G: string mLastKeys = _Keyb.GetLastKeysToString();
tho pressing Allt + ~ will output : “LeftAltOemTilde”
You can work around with collected held keys and return your desired char.
var mKeys = _Keyboard.GetLastKeys();
string mKeyStr = "";
//
for (int i = 0; i < mKeys.Length; i++)
{
if( mKeys[i] == Keys.OemTilde )
{
m_KeysStr += "~";
}
// Trap other special keys here
else
{
m_KeysStr += mKeys[i].ToString();
}
}
d
/// <summary>
/// Get all last keys currently being pressed down or
/// being held from this frame
/// </summary>
/// <returns>Returns Keys</returns>
public XFI.Keys[] GetLastKeys()
{
return __LastKeys;
}
/// <summary>
/// Get all last keys currently being pressed down or being
/// held from this frame in string.
/// </summary>
/// <returns>Returns Keys in string</returns>
public string GetLastKeysToString()
{
string m_KeysStr = "";
//
for (int i = 0; i < __LastKeys.Length; i++)
{
m_KeysStr += __LastKeys[i].ToString();
}
//
return m_KeysStr;
}
Keyboard.GetState(); only returns the keys on the keyboard which are pressed. It does not return characters that are being typed like: !"#¤&%&((/)@££$€$€{[]}. And Tilde cant be received if the user presses Alt + ~ in another window and then goes back to the game. One could make a giant switch for every single possible character but would still be kinda limited.
MonoGame has the GameWindow.TextInput event. It give you a character instead of a Keys member. In your Game1 class you can use the Window property to subscribe to it.