當前位置: 首頁>>代碼示例>>C#>>正文


C# System.ConsoleKeyInfo類代碼示例

本文整理匯總了C#中System.ConsoleKeyInfo的典型用法代碼示例。如果您正苦於以下問題:C# ConsoleKeyInfo類的具體用法?C# ConsoleKeyInfo怎麽用?C# ConsoleKeyInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConsoleKeyInfo類屬於System命名空間,在下文中一共展示了ConsoleKeyInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        static void Main(string[] args)
        {
            Brain brain = new Brain();
               // brain.doWork();
            Thread myBrainThread = new Thread(new ThreadStart(brain.doWork));
            myBrainThread.Start();

            ConsoleKeyInfo cki = new ConsoleKeyInfo();

            do
            {
                Console.WriteLine("\nPress 'x' key to logout.");
                while (Console.KeyAvailable == false)
                    Thread.Sleep(250); // Loop until input is entered.
                cki = Console.ReadKey(true);
               // Console.WriteLine("You pressed the '{0}' key.", cki.Key);
            } while (cki.Key != ConsoleKey.X);

            IPEndPoint registryEP = getEndpoint(ConfigurationManager.AppSettings["registryIP"], ConfigurationManager.AppSettings["registryPort"]);
            socket.Connect(registryEP);
            LogoutRequest lor = new LogoutRequest();
            byte[] logoutRequestMessage = lor.Encode();
            socket.Send(logoutRequestMessage, logoutRequestMessage.Length);
            Console.WriteLine("You have logged out.");
        }
開發者ID:JeffHemming,項目名稱:DSoak_First,代碼行數:25,代碼來源:Program.cs

示例2: ChangePlayerDirection

        static void ChangePlayerDirection(ConsoleKeyInfo key)
        {
            if (key.Key == ConsoleKey.W)
                firstPlayerDirection = up;

            if (key.Key == ConsoleKey.A)
                firstPlayerDirection = left;

            if (key.Key == ConsoleKey.D)
                firstPlayerDirection = right;

            if (key.Key == ConsoleKey.S)
                firstPlayerDirection = down;

            if (key.Key == ConsoleKey.UpArrow)
                secondPlayerDirection = up;

            if (key.Key == ConsoleKey.LeftArrow)
                secondPlayerDirection = left;

            if (key.Key == ConsoleKey.RightArrow)
                secondPlayerDirection = right;

            if (key.Key == ConsoleKey.DownArrow)
                secondPlayerDirection = down;
        }
開發者ID:GeriTeam,項目名稱:TelerikCSharp,代碼行數:26,代碼來源:TronGame.cs

示例3: BackwardWord

        /// <summary>
        /// Move the cursor back to the start of the current word, or if between words,
        /// the start of the previous word.  Word boundaries are defined by a configurable
        /// set of characters.
        /// </summary>
        public static void BackwardWord(ConsoleKeyInfo? key = null, object arg = null)
        {
            int numericArg;
            if (!TryGetArgAsInt(arg, out numericArg, 1))
            {
                return;
            }

            if (numericArg < 0)
            {
                if (CheckIsBound(ForwardWord))
                {
                    ForwardWord(key, -numericArg);
                }
                else
                {
                    NextWord(key, -numericArg);
                }
                return;
            }

            while (numericArg-- > 0)
            {
                int i = _singleton.FindBackwardWordPoint(_singleton.Options.WordDelimiters);
                _singleton._current = i;
                _singleton.PlaceCursor();
            }
        }
開發者ID:TyrelBaux,項目名稱:PSReadLine,代碼行數:33,代碼來源:Movement.cs

示例4: ExchangePointAndMark

 public static void ExchangePointAndMark(ConsoleKeyInfo? key = null, object arg = null)
 {
     var tmp = _singleton._mark;
     _singleton._mark = _singleton._current;
     _singleton._current = tmp;
     _singleton.PlaceCursor();
 }
開發者ID:dfinke,項目名稱:powershell,代碼行數:7,代碼來源:KillYank.cs

示例5: Enqueue

 public void Enqueue(ConsoleKeyInfo key)
 {
     lock (inputQueue)
     {
         inputQueue.Enqueue(new HumanInputItem(key, TimeSpan.Zero, HumanInputItem.NormalDelay));
     }
 }
開發者ID:adamabdelhamed,項目名稱:PowerArgs,代碼行數:7,代碼來源:CliKeyboardInputQueue.cs

示例6: Main

        static void Main(string[] args)
        {
            DNA firstStep = new DNA();
            spark = firstStep.Strand;
            bool t = false;
            int iteration = 0;

            ConsoleKeyInfo end = new ConsoleKeyInfo();
            Console.WriteLine("AI solver will attempt equations after GA designs them");
            NaturalSelection ns = new NaturalSelection();
            IntellegentDesign id = new IntellegentDesign();
            id.initialize();
            ns.darwin(spark);
            do
            {

                if (t==false)
                {
                    t = true;
                    Root(ns,id);
                }
                ns.darwin(id.dueronomy(ns.vA));
                Root(ns, id);
                if (iteration>100||novelAns>=cap)
                {
                    end = Console.ReadKey();
                    iteration = 0;
                    novelAns = 0;
                }
                iteration++;

            } while (end.Key != ConsoleKey.Escape);
        }
開發者ID:Jpound87,項目名稱:FirstIntellegence,代碼行數:33,代碼來源:Program.cs

示例7: ProcessKey

 protected override void ProcessKey(ConsoleKeyInfo consoleKey, InputState inputState)
 {
     switch(consoleKey.Key)
     {
         case ConsoleKey.Backspace:
             if(inputState.CarrageIndex > 0)
             {
                 inputState.Line.Remove(inputState.CarrageIndex - 1, 1);
                 inputState.CarrageIndex--;
                 Console.Write("\b");
                 inputState.RefreshTail(1);
             }
             break;
         case ConsoleKey.Delete:
             if(inputState.CarrageIndex < inputState.Line.Length)
             {
                 inputState.Line.Remove(inputState.CarrageIndex, 1);
                 inputState.RefreshTail(1);
             }
             break;
         default:
             base.ProcessKey(consoleKey, inputState);
             break;
     }
 }
開發者ID:mijay,項目名稱:Shell,代碼行數:25,代碼來源:ConsoleEditorWithRemove.cs

示例8: StartReading

        public void StartReading()
        {
            //engine.Connect();
            //engine.RemoteConnect("127.0.0.1", 3008);
            engine.RemoteConnect("127.0.0.1", 1726);

            ConsoleKeyInfo cki = new ConsoleKeyInfo();

            while (true)
            {
                try
                {
                    if (Console.KeyAvailable)
                    {
                        cki = Console.ReadKey(true);
                        if (cki.Key == ConsoleKey.X)
                        {
                            break;
                        }
                    }
                    engine.ProcessEvents(1000);
                }
                catch (EmoEngineException e)
                {
                    Console.WriteLine("{0}", e.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0}", e.ToString());
                }
            }
            engine.Disconnect();
        }
開發者ID:jfloodnet,項目名稱:BrainStore,代碼行數:33,代碼來源:MindReader.cs

示例9: Execute

 public void Execute(ConsoleKeyInfo request)
 {
     foreach (Filter filter in _filters) {
         filter.Execute(request);
     }
     _target.MovePlayer(request);
 }
開發者ID:Liutabu,項目名稱:Tankiukai,代碼行數:7,代碼來源:FilterChain.cs

示例10: ConsoleLongTaskWithCancel

		private static void ConsoleLongTaskWithCancel()
		{
			var cancelKey = new ConsoleKeyInfo('\u0011', ConsoleKey.Q, false, false, true);

			ConsoleTask.StartNew
				(
					cancellationToken =>
					{
						var stopwatch = new Stopwatch();
						stopwatch.Start();

						var i = 0;
						while (i++ < 10)
						{
							if (cancellationToken.IsCancellationRequested)
							{
								Console.WriteLine("Cancelled");
								return;
							}

							Console.WriteLine(stopwatch.ElapsedMilliseconds/1000);
							Thread.Sleep(1000);
						}
						Console.WriteLine("Completed");
					},
					cancelKey
				).Wait();
		}
開發者ID:toolmagic,項目名稱:RepeatableTask,代碼行數:28,代碼來源:Program.cs

示例11: ProcessKey

		public override bool ProcessKey(ConsoleKeyInfo key) {
			if (key.Key == ConsoleKey.Enter) {
				if (OnPressed != null) OnPressed (this);
				return true;
			}
			return false;
		}
開發者ID:ralfw,項目名稱:ShellForms,代碼行數:7,代碼來源:Button.cs

示例12: ProcessCommand

        private bool ProcessCommand(ConsoleKeyInfo key)
        {
            if (key.Modifiers.HasFlag(ConsoleModifiers.Control))
            {
                if (key.Key != ConsoleKey.Q) return false;
                _isExit = true;
                return true;
            }
            else if (key.Modifiers.HasFlag(ConsoleModifiers.Alt) || key.Modifiers.HasFlag(ConsoleModifiers.Shift))
            {
                return false;
            }

            if (_commands.ContainsKey(key.Key))
            {
                var command = _commands[key.Key];

                try
                {
                    Console.Clear();
                    command.Run();
                }
                catch (Exception e)
                {
                    Console.Clear();
                    Console.WriteLine($"There were some errors while running command {command}");
                    e.WriteLog();
                    ToMainMenu();
                }
                return true;
            }
            else
                return false;
        }
開發者ID:deep-dark-server,項目名稱:GoldMine,代碼行數:34,代碼來源:Program.cs

示例13: ModoDeJogo

 public ModoDeJogo()
 {
     cki = new ConsoleKeyInfo();
     tabuleiro = new Tabuleiro();
     acabou = false;
     selecionarModoDeJogo();
 }
開發者ID:luturol,項目名稱:LearningCSharp,代碼行數:7,代碼來源:ModoDeJogo.cs

示例14: ShowMenu

        public static void ShowMenu()
        {
            Console.WriteLine("*** MENU ***");
            Console.WriteLine("1. Overzicht mp3 spelers");
            Console.WriteLine("2. Overzicht voorraad");
            Console.WriteLine("3. Muteer voorraad");
            Console.WriteLine("4. Statistieken");
            Console.WriteLine("5. Toevoegen mp3 speler");
            Console.WriteLine("6. ");
            Console.WriteLine("7. ");
            Console.WriteLine("8. Toon menu");
            Console.WriteLine("9. Exit");

            //Invoer wordt gelezen
            ConsoleKeyInfo userinput = new ConsoleKeyInfo();
            userinput = Console.ReadKey();

            while (userinput.KeyChar != '9')
            {
                switch (userinput.KeyChar)
                {
                    case '1':
                        Console.Clear();
                        Console.WriteLine("\rGekozen actie: {0}. Overzicht mp3 spelers\n", userinput.KeyChar);
                        //oude optie >> Gegevensspelers.showmp3();
                        Gegevenslist.overzichtzicht();
                        break;
                    case '2':
                        Console.Clear();
                        Console.WriteLine("\rGekozen actie: {0}. Overzicht voorraad\n", userinput.KeyChar);
                        Gegevenslist.showvoorraad();
                        break;
                    case '3':
                        Console.Clear();
                        Console.WriteLine("\rGekozen actie: {0}. Muteer voorraad\n", userinput.KeyChar);
                        Gegevenslist.muteren();
                        break;
                    case '4':
                        Console.Clear();
                        Console.WriteLine("\rGekozen actie: {0}. Statistieken", userinput.KeyChar);
                        Gegevenslist.tien();
                        break;
                    case '5':
                        Console.Clear();
                        Console.WriteLine("\rGekozen actie: {0}. Toevoegen mp3 speler", userinput.KeyChar);
                        Gegevenslist.mp3toevoeg();
                        break;
                    case '6':
                        break;
                    case '7':
                        break;
                    case '8':
                        voorraad.toonmenu();
                        break;
                    default:
                        break;
                }
                userinput = Console.ReadKey(true);
            }
        }
開發者ID:MisterN95,項目名稱:Soundsharp-Syntax,代碼行數:60,代碼來源:Hoofdmenu.cs

示例15: TryHandleKeyboardInput

        public override bool TryHandleKeyboardInput(ConsoleKeyInfo key)
        {
            List<KeyboardEventHandler> potentialHandlers = new List<KeyboardEventHandler>();

            if(Application.FocusManager.FocusedControl != null)
            {
                Application.FocusManager.FocusedControl.HandleKeyInput()
            }

            if(key.Modifiers.HasFlag(ConsoleModifiers.Alt))
            {

            }
            else if (key.Modifiers.HasFlag(ConsoleModifiers.Control))
            {

            }
            else if (key.Modifiers.HasFlag(ConsoleModifiers.Shift))
            {

            }
            else
            {

            }

            handlers.Peek()[KeyboardEventHandler.CreateLookupKey(key.Key, KeyboardEventMatchMode.NoModifiers)];
        }
開發者ID:adamabdelhamed,項目名稱:PowerArgs,代碼行數:28,代碼來源:KeyboardInputManager.cs


注:本文中的System.ConsoleKeyInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。