I'm making a basic console app.
I basically want to wait for a particular key press like F1, F2 ... or if non is pressed, the user can type in the entire command. And the problem I'm facing is that when I call Console.ReadKey()
it always suppresses the first character in the user's input. This will break the console history and the command itself. I want to read only functional keys, but when the user wants to type a normal command like 'echo' i don't want the 'e' to be treated as a keypress but as an entire command.
Examples:
User presses F1 which means they don't want to input a command so the F1 logic will execute and the user will be able to make a new interaction (command or key press)
User presses 'e' which means they want to type an entire command like 'echo' so the program will wait for a next line (enter)
Codepublic string[] Input() { Console.Write(Core.commandChar); var KP = Console.ReadKey(); if (KP.Key == ConsoleKey.F1) { inputs = new string[] { "echo", "test", "" }; return inputs; } inputs = (KP.KeyChar+Console.ReadLine()).Split(' '); return inputs; }
Is there a way to pull this off?