static void DeviceOperations(IRokuRemote roku) { Console.WriteLine($"You chose device id {roku.Info.Id}"); while (true) { Console.WriteLine("1) Go to the home screen"); Console.WriteLine("2) Launch an application"); Console.WriteLine("3) Show the current active application"); Console.WriteLine("4) Keypress"); Console.WriteLine("5) Search"); Console.WriteLine("6) Save App Icons"); var choice = ParseChoice("Make a selection: ", 1, 6); if (choice == null) { Console.WriteLine($"leaving {roku.Info.Id}"); break; } if (choice < 0) { continue; } switch (choice.Value) { case 1: Console.WriteLine($"Sending {roku.Info.Id} to the home screen."); roku.KeypressAsync(CommandKeys.Home).Wait(); break; case 2: LaunchApp(roku); break; case 3: ShowActiveApp(roku); break; case 4: HandleKeypress(roku); break; case 5: Search(roku); break; case 6: SaveAppIcons(roku); break; default: break; } Console.WriteLine(); } }
static void HandleKeypress(IRokuRemote roku) { var controlKeys = new Dictionary <ConsoleKey, CommandKeys> { { ConsoleKey.B, CommandKeys.Back }, { ConsoleKey.I, CommandKeys.Info }, { ConsoleKey.Spacebar, CommandKeys.Select }, { ConsoleKey.P, CommandKeys.Play }, { ConsoleKey.D, CommandKeys.Fwd }, { ConsoleKey.R, CommandKeys.Rev }, }; var altKeys = new Dictionary <ConsoleKey, CommandKeys> { { ConsoleKey.S, CommandKeys.Search }, { ConsoleKey.R, CommandKeys.InstantReplay }, }; var commandKeys = new Dictionary <ConsoleKey, CommandKeys> { { ConsoleKey.Enter, CommandKeys.Select }, { ConsoleKey.Home, CommandKeys.Home }, { ConsoleKey.RightArrow, CommandKeys.Right }, { ConsoleKey.DownArrow, CommandKeys.Down }, { ConsoleKey.LeftArrow, CommandKeys.Left }, { ConsoleKey.UpArrow, CommandKeys.Up }, { ConsoleKey.Backspace, CommandKeys.Backspace }, { ConsoleKey.MediaPlay, CommandKeys.Play }, { ConsoleKey.MediaNext, CommandKeys.Fwd }, { ConsoleKey.MediaPrevious, CommandKeys.Rev }, }; Console.Write("Enter keys: "); while (true) { var keyInfo = Console.ReadKey(true); if (keyInfo.Key == ConsoleKey.Escape) { break; } CommandKeys?commandKey = null; if (keyInfo.Modifiers == ConsoleModifiers.Control) { if (controlKeys.ContainsKey(keyInfo.Key)) { commandKey = controlKeys[keyInfo.Key]; } } else if (keyInfo.Modifiers == ConsoleModifiers.Alt) { if (altKeys.ContainsKey(keyInfo.Key)) { commandKey = altKeys[keyInfo.Key]; } } else if (commandKeys.ContainsKey(keyInfo.Key)) { commandKey = commandKeys[keyInfo.Key]; } Func <ICommandResponse> command; if (commandKey != null) { command = () => roku.KeypressAsync(commandKey.Value).Result; } else { command = () => roku.KeypressAsync(keyInfo.KeyChar).Result; } if (!command().IsSuccess) { Console.Write("-DEVICE ERROR"); } } }