当前位置: 首页>>代码示例>>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;未经允许,请勿转载。