public bool KeyDown(KeyboardInputEventArgs e)
{
if (isSelected)
{
if (e.Key == KeyboardKeys.Enter || e.Key == KeyboardKeys.Return)
{
isSelected = false;
}
else if (e.Key == KeyboardKeys.Back)
{
if (SelectedText.Length > 0)
{
DeleteSelectedText();
}
else if (Text.Length > 0)
{
Text = Text.Substring(0, Text.Length - 1);
}
}
else if (e.Key == KeyboardKeys.Delete)
{
if (SelectedText.Length > 0)
{
DeleteSelectedText();
}
}
else if (e.Key == KeyboardKeys.A && e.ModifierKeys == KeyboardKeys.Control)
{
SelectedText = Text;
SelectedTextIndex = 0;
}
else if (char.IsLetterOrDigit(e.CharacterMapping.Character) ||
char.IsLetterOrDigit(e.CharacterMapping.Shifted) ||
char.IsSymbol(e.CharacterMapping.Character) ||
char.IsSymbol(e.CharacterMapping.Shifted) ||
char.IsPunctuation(e.CharacterMapping.Character) ||
char.IsPunctuation(e.CharacterMapping.Shifted) ||
char.IsWhiteSpace(e.CharacterMapping.Character))
{
if (SelectedText.Length > 0)
{
ReplaceSelectedText(e.Shift ? e.CharacterMapping.Shifted.ToString() : e.CharacterMapping.Character.ToString());
return true;
}
string prevText = Text;
Text = Text + (e.Shift ? e.CharacterMapping.Shifted : e.CharacterMapping.Character);
text.SetText(Text);
if (text.GetWidth() > width - 8)
{
text.SetText(prevText);
Text = prevText;
}
}
else if (e.Key == KeyboardKeys.Decimal)
{
if (SelectedText.Length > 0)
{
ReplaceSelectedText(".");
return true;
}
string prevText = Text;
Text = Text + ".";
text.SetText(Text);
if (text.GetWidth() > width - 8)
{
text.SetText(prevText);
Text = prevText;
}
}
return true;
}
return false;
}