Matomat/Matomat/Input/KeyboardReader.cs
2013-07-14 20:59:37 +00:00

50 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Matomat.Helper;
namespace Matomat.Input
{
class KeyboardReader
{
public string getCodeID(string text)
{
Factory.getLCD().print(text);
string str = "";
while (true)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo k = Console.ReadKey(true);
if (k.Key == ConsoleKey.Enter)
{
break;
}
else if (k.Key == ConsoleKey.Backspace)
{
if(str.Length > 0)
str = str.Substring(0, str.Length - 1);
}
else if (k.Key == ConsoleKey.Escape)
{
throw new ArgumentOutOfRangeException("Eingabe abgebrochen");
}
else
{
str = str + k.KeyChar.ToString();
}
Factory.getLCD().print(text + "\n" + str.PadRight(38,' '));
}
System.Threading.Thread.Sleep(10);
}
try
{
return str.Trim();
}
catch (Exception) { }
return "";
}
}
}