Convert KeyDown keys to one string C#
Rather than adding to a list why not build up the string:
private string input;
private bool shiftPressed;
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
{
shiftPressed = true;
}
else
{
if (e.Key >= Key.D0 && e.Key <= Key.D9)
{
// Number keys pressed so need to so special processing
// also check if shift pressed
}
else
{
input += e.Key.ToString();
}
}
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
{
shiftPressed = false;
}
}
Obviously you need to reset input
to string.Empty
when you start the next transaction.