diff --git a/Utils.cs b/Utils.cs index a512dd3..7c636e8 100644 --- a/Utils.cs +++ b/Utils.cs @@ -12,9 +12,16 @@ namespace SteamGuard do { key = Console.ReadKey(true); - if ((int)key.Key >= 65 && (int)key.Key <= 90) + if (((int)key.Key) >= 65 && ((int)key.Key <= 90)) { - text.Insert(cursorIndex, key.KeyChar.ToString()); + if (cursorIndex == 0 || cursorIndex == text.Length - 1) + { + text += key.KeyChar.ToString(); + } + else + { + text.Insert(cursorIndex, key.KeyChar.ToString()); + } cursorIndex++; } else if (key.Key == ConsoleKey.Backspace && cursorIndex > 0) @@ -35,10 +42,17 @@ namespace SteamGuard { cursorIndex = 0; } - else if (cursorIndex > text.Length) + else if (text.Length == 0 && cursorIndex > text.Length) + { + cursorIndex = 0; + } + else if (text.Length != 0 && cursorIndex >= text.Length) { cursorIndex = text.Length - 1; } + + // For debugging: + // Console.Title = string.Format("{0}/{1} - {2} ({3}) - {4}", cursorIndex, text.Length, key.Key.ToString(), (int)key.Key, text); } while (key.Key != ConsoleKey.Enter); return text; }