protected virtual string RenderMenu(IList <OptionChoice> optionChoices, RenderContext context) { Console.CursorVisible = false; ConsoleKey?key = null; var index = 0; while (key != ConsoleKey.Enter) { if (key != null) { Console.SetCursorPosition(0, Console.CursorTop - optionChoices.Count); } RenderMenu(optionChoices, optionChoices[index], context); key = Console.ReadKey(true).Key; if (key == ConsoleKey.UpArrow) { index = Math.Max(0, index - 1); } if (key == ConsoleKey.DownArrow) { index = Math.Min(optionChoices.Count - 1, index + 1); } } Console.CursorVisible = true; return(optionChoices[index].Id); }
private static async Task Main(string[] _) { CreateLogger(); using (var channelFactory = new ChannelFactory <ISimpleEdgeService>(new NetTcpBinding(), new EndpointAddress(SimpleEdgeService.BaseAddress))) { channelFactory.Endpoint.AddBehavior <InspectorBehavior <TracingInspector> >(); var channel = channelFactory.CreateChannel(); Log.Information("Host opened"); var index = 1; ConsoleKey?keyPressed = null; while (keyPressed != ConsoleKey.Enter && keyPressed != ConsoleKey.Q && keyPressed != ConsoleKey.X) { var delay = TimeSpan.FromSeconds(ConsoleKey.D0 <= keyPressed && ConsoleKey.D9 >= keyPressed ? 0 : 5); Log.Information("call delayed for {TimeSpan} seconds", delay); var result = await channel.Echo(Process.GetCurrentProcess() .Id + " echo " + index, delay); Log.Information("{Result}", result); keyPressed = Console.ReadKey().Key; index++; } } Log.CloseAndFlush(); }
public static ConsoleKey?GetKey() { ConsoleKey?k_temp = k; k = null; return(k_temp); }
public static void Main(string[] args) { const string RESTART_MESSAGE = "Press Escape to quit or anything else to start again . . ."; string messageRemover = new string(' ', RESTART_MESSAGE.Length); ConsoleKey?pressedKey = null; int number; while (pressedKey != ConsoleKey.Escape) { CursorVisible = true; do { Write("Enter a number greater or equal 0: "); } while (!int.TryParse(ReadLine(), out number) || number < 0); CursorVisible = false; int result = 1; for (int i = number; i > 0; i--) { result *= i; } WriteLine($"{number}! = {result}"); Write(RESTART_MESSAGE); pressedKey = ReadKey(true).Key; Write("\r" + messageRemover + "\n"); } }
public void Run() { ConsoleKey?key = null; WriteWelcomeMessage(); do { if (key == ConsoleKey.C) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Sending Create Application Command"); Console.ResetColor(); var command = new CreateApplicationCommand() { ApplicationId = Guid.NewGuid(), FirstName = "foo", LastName = "bar", TTL = DateTime.Now.AddSeconds(5) }; _bus.Send(command); } key = Console.ReadKey().Key; Console.WriteLine(); } while (key != ConsoleKey.Q); }
private static void HandleEvents() { while (true) { key = Console.ReadKey(true).Key; } }
public void Start() { Console.WriteLine("Client started"); client = new Network.Client(4445); client.PacketRecieved += Client_PacketRecieved; client.Start(); ConsoleKey?key = null; while (key != ConsoleKey.Q) { if (Console.KeyAvailable) { key = Console.ReadKey(true).Key; //If we're dead, check for the respawn key press if (dead) { if (key == ConsoleKey.R) { var respawnRequest = new Event(); respawnRequest.eventType = (int)EventType.Request; respawnRequest.specificEvent = (int)Request.Spawn; var newPacket = new Packet(respawnRequest); client.Send(newPacket.ToBytes()); } } else { switch (key) { case ConsoleKey.W: client.SendDirectionChange(0); break; case ConsoleKey.D: client.SendDirectionChange(1); break; case ConsoleKey.S: client.SendDirectionChange(2); break; case ConsoleKey.A: client.SendDirectionChange(3); break; default: break; } } } Thread.Sleep(10); } client.Shutdown(); }
private void Choice(ref List <Developer> list, int page, params byte[] coordinates) { coordinates.ToList(); Console.CursorVisible = true; int x = 0, y = 3; int i = page; Console.SetCursorPosition(coordinates[x], y); Input inp = new Input(); ConsoleKey?key = null; while ((key != ConsoleKey.Escape) && (key != ConsoleKey.Delete)) { key = inp.InputKey(ConsoleKey.LeftArrow, ConsoleKey.RightArrow, ConsoleKey.DownArrow, ConsoleKey.UpArrow, ConsoleKey.Delete, ConsoleKey.Escape); switch (key) { case ConsoleKey.RightArrow: if (x + 1 <= coordinates.Count() - 1) { x++; } break; case ConsoleKey.LeftArrow: if (x - 1 >= 0) { x--; } break; case ConsoleKey.DownArrow: if (y + 1 <= list.Count * 2) { y += 2; i++; } break; case ConsoleKey.UpArrow: if (y - 1 >= 3) { y -= 2; i--; } break; case ConsoleKey.Delete: list.RemoveAt(i); Write_Page(page, list); break; //case ConsoleKey.Enter: // break; } Console.SetCursorPosition(coordinates[x], y); } Console.CursorVisible = false; }
/// <summary> /// Взаємодія з клієнтом /// </summary> private void Entry() { // Примітка. Блокувати не потрібно там де є очікування курсора, // так як не буде можливості оновити меню коректно без артефактів // Обробка натискань while (true) { // Результат замовлення Order(); // Головне меню вибору MenuChange(); // клавіша вводу ConsoleKey?key = Console.ReadKey(true).Key; // дія згідно вибору switch (key) { case ConsoleKey.N: // очистить if (presenter.Data.IsGlass) { PressedN.Invoke(); } break; case ConsoleKey.G: // стаканчик PressedG.Invoke(); break; case ConsoleKey.D: // напиток if (presenter.Data.IsGlass) { PressedD.Invoke(); } break; case ConsoleKey.A: // добавка if (presenter.Data.IsGlass) { PressedA.Invoke(); } break; case ConsoleKey.P: // оплата if (presenter.Data.GetDrinks().Count > 0) { PressedP.Invoke(); } break; case ConsoleKey.Escape: // виход Environment.Exit(0); break; } } }
public static void WaitForKey(ConsoleKey key) { ConsoleKey?lastKey = null; while (lastKey != key) { key = Console.ReadKey(true).Key; } }
public static ConsoleKey AskYesNoQuestion(string question, ConsoleKey?defaultAnswer = null) { if (defaultAnswer == null) { return(AskYesNoQuestionWithoutDefaultAnswer(question)); } return(AskYesNoQuestionWithDefaultAnswer(question, defaultAnswer.Value)); }
/* * * * Är tillbaka kl 13 * * * * * * */ public int ShowMenu(string prompt, List <string> options) { if (options == null || options.Count == 0) { throw new ArgumentException("Cannot show a menu for an empty array of options."); } Console.WriteLine(prompt); int selected = 0; // Hide the cursor that will blink after calling ReadKey. Console.CursorVisible = false; ConsoleKey?key = null; while (key != ConsoleKey.Enter) { // If this is not the first iteration, move the cursor to the first line of the menu. if (key != null) { Console.CursorLeft = 0; Console.CursorTop = Console.CursorTop - options.Count; } // Print all the options, highlighting the selected one. for (int i = 0; i < options.Count; i++) { var option = options[i]; if (i == selected) { Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine("- " + option); Console.ResetColor(); } // Read another key and adjust the selected value before looping to repeat all of this. key = Console.ReadKey().Key; if (key == ConsoleKey.DownArrow) { selected = Math.Min(selected + 1, options.Count - 1); } else if (key == ConsoleKey.UpArrow) { selected = Math.Max(selected - 1, 0); } } // Reset the cursor and return the selected option. Console.CursorVisible = true; return(selected); }
internal bool OperateIfKeyPressed() { PressedKey = null; if (Console.KeyAvailable) { PressedKey = Console.ReadKey(false).Key; } return(PressedKey != null); }
public UIController(Display display, GameState gameState, GameCoordinator gameCoordinator) { _display = display; _view = new View(_display); _gameState = gameState; _gameCoordinator = gameCoordinator; _input = null; _selectingWildcardColor = false; _selectedWildCardHandIndex = 0; _winTransmitted = false; }
public static bool AskCountinue() { ConsoleKey?decision = null; while (decision != ConsoleKey.Enter && decision != ConsoleKey.Escape) { Console.WriteLine("Enter - Продолжить, Esc - Отменить\r\n"); decision = Console.ReadKey(false).Key; } return(decision == ConsoleKey.Enter); }
public static bool SameAs(this ConsoleKey lhs, ConsoleKey?rhs) { if (rhs == null) { return(false); } char lkey = (char)lhs; char rkey = (char)rhs; return(char.ToUpper(lkey) == char.ToUpper(rkey)); }
public static void Run() { int fps = 1; int frms = 1000 / fps; Console.SetCursorPosition(0, 0); Console.WriteLine("[X] - Press ESC to stop"); ConsoleKey?lastKeyPressed = null; Console.CursorVisible = false; char c = 'X'; var sw = new Stopwatch(); do { sw.Start(); while (!Console.KeyAvailable) { if (lastKeyPressed.HasValue) { char tmp = (char)lastKeyPressed.Value; if (c != tmp && char.IsLetterOrDigit(tmp)) { c = tmp; } else if (lastKeyPressed == ConsoleKey.UpArrow && fps < 1000) { fps += 1; } else if (lastKeyPressed == ConsoleKey.DownArrow && fps > 1) { fps -= 1; } frms = 1000 / fps; lastKeyPressed = null; Console.SetCursorPosition(0, 2); Console.WriteLine($"FPS={fps} FRMS={frms} "); } if (sw.ElapsedMilliseconds >= frms) { // Do something Console.ForegroundColor = (ConsoleColor)(_rand.Next(16)); Console.SetCursorPosition(1, 0); Console.Write(c); sw.Restart(); } } sw.Stop(); } while ((lastKeyPressed = Console.ReadKey(true).Key) != ConsoleKey.Escape); Console.CursorVisible = true; }
protected override int OnPathEntered(string path) { Console.Clear(); Console.WriteLine("Loading GPIO state from file : {0}.", path); Console.WriteLine(); try { string serializedState = File.ReadAllText(path); Console.WriteLine(serializedState); Console.WriteLine(); ConsoleKey?key = null; if (!handsOffMode) { Console.WriteLine("Press [Y] to accept and load this state or any other key to abort..."); key = Console.ReadKey(true).Key; } if (handsOffMode || key == ConsoleKey.Y) { String log = (new SerializationTool()).DeserializeState(serializedState, out tagsState); Console.Clear(); Console.WriteLine(log); Console.WriteLine(); Console.WriteLine("State loaded, press any key to continue..."); if (!handsOffMode) { Console.ReadKey(true); } return(RETURN_VALUE_OK); } else { Console.WriteLine("Aborted, press any key to continue..."); if (!handsOffMode) { Console.ReadKey(true); } return(RETURN_VALUE_ESCAPED); } } catch (Exception e) { Console.WriteLine(String.Format("Error while deserializing GPIO state {0}, press any key to continue...", e.Message)); if (!handsOffMode) { Console.ReadKey(true); } return(RETURN_VALUE_ERROR); } }
/// <summary> /// Считывает нажатые клавишы и возвращает только те, которые были переданны в метод /// </summary> /// <param name="keys"></param> /// <returns></returns> public ConsoleKey InputKey(params ConsoleKey?[] keys) { ConsoleKeyInfo keyInfo; ConsoleKey? key = null; while (!keys.Contains(key)) { keyInfo = Console.ReadKey(true); key = keyInfo.Key; } return((ConsoleKey)key); }
public static string MenuOptions(List <string> input, string type) { Console.WriteLine(); Console.WriteLine(type); var options = input; int selected = 0; Console.CursorVisible = false; ConsoleKey?key = null; //Until the user presses enter the loop will continue to run while (key != ConsoleKey.Enter) { //Keeps track of what position the cursor has if (key != null) { Console.CursorLeft = 0; Console.CursorTop = Console.CursorTop - options.Count; } //Change the color at the cursor position for (int i = 0; i < options.Count; i++) { var option = options[i]; if (i == selected) { Console.ForegroundColor = ConsoleColor.Yellow; } Console.WriteLine("- " + option); Console.ResetColor(); } //Moves the cursor up or down key = Console.ReadKey().Key; if (key == ConsoleKey.DownArrow) { selected = Math.Min(selected + 1, options.Count - 1); } else if (key == ConsoleKey.UpArrow) { selected = Math.Max(selected - 1, 0); } } Console.CursorVisible = true; //Return the selected option as lowercase return(options[selected].ToLower()); }
private void PullingCard(Deck deck, ConsoleKey?pullCard) { ConsoleKey?choice = pullCard; while (true) { //Stops if all cards are pulled if (deck.Cards.Count == 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("You are out of cards!"); Console.ResetColor(); BackToMenuQuestion(); break; } if (choice.Equals(ConsoleKey.D1)) { CardDraw(deck); //Asks for continuation Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("1(Pull again) 2(Shuffle) 3(Sort deck) or (any other key to stop)"); Console.ResetColor(); } choice = Console.ReadKey(true).Key; if (choice == ConsoleKey.D1) { continue; } else if (choice == ConsoleKey.D2) { deck.ShuffleDeck(); Console.WriteLine("Deck shuffled!"); } else if (choice == ConsoleKey.D3) { deck.SortDeck(); Console.WriteLine("Deck Sorted"); } else { Console.WriteLine("You stopped"); BackToMenuQuestion(); break; } } }
private void FireKeyActionEvent(ConsoleKey?key = null) { if (key.HasValue && key.Value == ConsoleKey.Q) { return; } var keyAction = new KeyAction(key) .WithOldStep(_positionState.OldStep_X, _positionState.OldStep_Y) .WithOldPostion(_positionState.OldPosition_X, _positionState.OldPosition_Y) .WithNewPosition(_positionState.Position_X, _positionState.Position_Y); KeyActionEvent.Invoke(this, keyAction); }
static void Main(string[] args) { InitMainMenu(); DrawScreen(); while (state != GameState.EXIT) { int time = -DateTime.Now.Millisecond; ConsoleKey?button = null; while (Console.KeyAvailable) { button = Console.ReadKey(true).Key; } switch (button) { case ConsoleKey.W: cursor.y = (cursor.y - 15 - 1 + 3) % 3 + 15; break; case ConsoleKey.S: cursor.y = (cursor.y - 15 + 1 + 3) % 3 + 15; break; case ConsoleKey.Enter: switch ((cursor.y - 15) % 3) { case 0: RunGame(); break; case 1: ShowInstructions(); break; case 2: state = GameState.EXIT; break; } break; } if (button != null) { DrawScreen(); } time = +DateTime.Now.Millisecond; if (state != GameState.EXIT) { System.Threading.Thread.Sleep(200); } } }
public static string ShowMenu(string prompt, string[] options) { Console.WriteLine(prompt); int selected = 0; // Hide the cursor that will blink after calling ReadKey. Console.CursorVisible = false; ConsoleKey?key = null; while (key != ConsoleKey.Enter) { // If this is not the first iteration, move the cursor to the first line of the menu. if (key != null) { Console.CursorLeft = 0; Console.CursorTop = Console.CursorTop - options.Length; } // Print all the options, highlighting the selected one. for (int i = 0; i < options.Length; i++) { var option = options[i]; if (i == selected) { Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine("- " + option); Console.ResetColor(); } // Read another key and adjust the selected value before looping to repeat all of this. key = Console.ReadKey().Key; if (key == ConsoleKey.DownArrow) { selected = Math.Min(selected + 1, options.Length - 1); } else if (key == ConsoleKey.UpArrow) { selected = Math.Max(selected - 1, 0); } } // Reset the cursor and perform the selected action. Console.CursorVisible = true; Console.Clear(); return(options[selected]); }
public void LitsenPlayerMoves() { new Thread(() => { Console.SetCursorPosition(XPosition, YPosition); for (ConsoleKey?key = null; key != ConsoleKey.Escape; key = Console.ReadKey().Key) { switch (key) { case ConsoleKey.LeftArrow: { CheckXDirection(Direction.Left); } break; case ConsoleKey.RightArrow: { CheckXDirection(Direction.Rigth); } break; case ConsoleKey.UpArrow: { CheckYDirection(Direction.Up); } break; case ConsoleKey.DownArrow: { CheckYDirection(Direction.Down); } break; case ConsoleKey.Enter: { CheckMovement(); } break; } CurrentBoard.DrawBoard(); CurrentBoard.DrawSpots(); DrawScoreBoard(); CurrentBoard.DrawControlsHelp(); CurrentBoard.DrawErrorMessages(); Console.SetCursorPosition(XPosition, YPosition); } }).Start(); }
public void Wait(ConsoleKey?stopKey = null) { if (stopKey.HasValue) { WriteLineInColor($"Press { stopKey.ToString() } for stop..."); while (Console.ReadKey().Key != stopKey) { } } else { WriteLineInColor("Press any key for stop..."); Console.ReadKey(); } }
//public static List<Gem> _gems = new List<Gem>(); public static void Run() { int fps = 3; int frms = 1000 / fps; //Console.SetCursorPosition(0, 0); ConsoleKey?lastKeyPressed = null; Console.CursorVisible = false; var flipper = _rand.Next(1) == 0; ReadInGameArray(); DrawBackground(); var sw = new Stopwatch(); do { sw.Start(); while (!Console.KeyAvailable) { // handle controls! if (lastKeyPressed.HasValue) { //char tmp = (char)lastKeyPressed.Value; //if (c != tmp && char.IsLetterOrDigit(tmp)) c = tmp; //else if (lastKeyPressed == ConsoleKey.UpArrow && fps < 1000) fps += 1; //else if (lastKeyPressed == ConsoleKey.DownArrow && fps > 1) fps -= 1; frms = 1000 / fps; lastKeyPressed = null; } if (sw.ElapsedMilliseconds >= frms) { DoGemMovementLogic(ref flipper); // Do something //Console.SetCursorPosition(1, 0); //Console.Write(c); RenderGems(); sw.Restart(); } } sw.Stop(); } while ((lastKeyPressed = Console.ReadKey(true).Key) != ConsoleKey.Escape); Console.CursorVisible = true; }
public void ComputerGuess(int low, int high) { bool correct; int count = 0; do { count++; Console.Clear(); int temp; if (high == low + 1) { temp = high; } else { temp = (low + high) / 2; } Console.WriteLine(temp); Console.WriteLine("Is the number correct?(y/n)"); ConsoleKey?v = Console.ReadKey().Key; Console.WriteLine(); correct = v == ConsoleKey.Y ? true : false; if (correct == false) { Console.WriteLine("Is (1)high or (2)low?"); ConsoleKey?x = null; x = Console.ReadKey().Key; Console.WriteLine(); if (x == ConsoleKey.D1) { high = temp; } else { low = temp; } } } while (correct == false); Console.WriteLine($"It took {count} to guess correctly"); Console.ReadLine(); }
public static int ShowMenu(string prompt, List <string> options) { Console.WriteLine(prompt); int selected = 0; // Hide the cursor that will blink after calling ReadKey. Console.CursorVisible = false; ConsoleKey?key = null; while (key != ConsoleKey.Enter) { // If this is not the first iteration, move the cursor to the first line of the menu. if (key != null) { Console.CursorLeft = 0; Console.CursorTop -= options.Count; } // Print all the options, highlighting the selected one. for (int i = 0; i < options.Count; i++) { var option = options[i]; if (i == selected) { Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine("- " + option); Console.ResetColor(); } // Read another key and adjust the selected value before looping to repeat all of this. key = Console.ReadKey().Key; selected = key switch { ConsoleKey.DownArrow => Math.Min(selected + 1, options.Count - 1), ConsoleKey.UpArrow => Math.Max(selected - 1, 0), _ => selected }; } // Reset the cursor and return the selected option. Console.CursorVisible = true; return(selected); } }
public void NullableEnumGetHashCodeInvocation() { ConsoleKey?e = GetHashCode() % 2 == 0 ? ConsoleKey.Clear : ConsoleKey.Add; object boxedComparand = ConsoleKey.Clear; #if NETFRAMEWORK Allocations.AssertAllocates(() => e.GetHashCode()); Allocations.AssertAllocates(() => e.ToString()); Allocations.AssertNoAllocations(() => e.Equals(null)); // shortcut Allocations.AssertAllocates(() => e.Equals(boxedComparand)); #else Allocations.AssertNoAllocations(() => e.GetHashCode()); // optimized by runtime Allocations.AssertAllocates(() => e.ToString()); Allocations.AssertNoAllocations(() => e.Equals(null)); // shortcut Allocations.AssertAllocates(() => e.Equals(boxedComparand)); #endif }