Been writing a class for a main menu, there's a play button and when pressed it goes to a window that asks for coordinates, sadly when writing with the keys and using the numbers the output is either D1, D2, D3... and so on, or NumPad1, NumPad2... and such. What I want is for the output to be just the number itself rather than the key name.
private string Coordinates = string.Empty;
private SpriteFont font;
private Keys[] lastPressedKeys = new Keys[5];
public void GetKeys()
{
KeyboardState kbState = Keyboard.GetState();
Keys[] pressedKeys = kbState.GetPressedKeys();
foreach (Keys key in lastPressedKeys)
{
if (!pressedKeys.Contains(key))
{
//key is no longer pressed
OnKeyUp(key);
}
}
foreach (Keys key in pressedKeys)
{
if (!lastPressedKeys.Contains(key))
{
OnKeyDown(key);
}
}
lastPressedKeys = pressedKeys;
}
public void OnKeyUp(Keys key)
{
}
public void OnKeyDown(Keys key)
{
KeyboardState kbState = Keyboard.GetState();
if (key == Keys.Back && Coordinates.Length > 0)
{
Coordinates = Coordinates.Remove(Coordinates.Length - 1);
}
else
{
Coordinates += key.ToString();
}
}
Here's the whole class https://pastebin.com/ZJqXx0zc
is there something wrong with using ToString? Or should I be using something different for numbers?