• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ConsoleKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ConsoleKey的典型用法代码示例。如果您正苦于以下问题:C# ConsoleKey类的具体用法?C# ConsoleKey怎么用?C# ConsoleKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConsoleKey类属于命名空间,在下文中一共展示了ConsoleKey类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: KeysPressed

		public override void KeysPressed(ConsoleKey _key, EKeyModifiers _modifiers)
		{
			switch (_key)
			{
				case ConsoleKey.A:
					Constants.WORLD_MAP_SIZE = 32;
					Constants.WORLD_SEED = new Random().Next(10000);
					//Constants.WORLD_SEED = 2;
                    m_game.Run();
					break;
				case ConsoleKey.B:
					Constants.WORLD_MAP_SIZE = 100;
					Constants.WORLD_SEED = new Random().Next(10000);
                    m_game.Run();
					break;
				case ConsoleKey.C:
					Constants.WORLD_MAP_SIZE = 1;
					Constants.WORLD_SEED = 1;
                    m_game.Run();
					break;
				case ConsoleKey.D:
					Constants.WORLD_MAP_SIZE = 1;
					Constants.WORLD_SEED = 2;
                    m_game.Run();
					break;
				case ConsoleKey.E:
					Constants.WORLD_MAP_SIZE = 1;
					Constants.WORLD_SEED = 0;
                    m_game.Run();
					break;
			}
		}
开发者ID:Foxbow74,项目名称:my-busycator,代码行数:32,代码来源:StartSelectorUiBlock.cs


示例2: Action

 public void Action(ConsoleKey key)
 {
     Console.Clear();
     switch (key)
     {
         case ConsoleKey.D0:
             break;
         case ConsoleKey.D1:
             break;
         case ConsoleKey.D2:
             break;
         case ConsoleKey.D3:
             break;
         case ConsoleKey.D4:
             break;
         case ConsoleKey.D5:
             break;
         case ConsoleKey.D6:
             break;
         case ConsoleKey.D7:
             break;
         case ConsoleKey.D8:
             break;
         case ConsoleKey.D9:
             break;
         default:
             break;
     }
 }
开发者ID:enchman,项目名称:jobboard,代码行数:29,代码来源:ViewConsole.cs


示例3: ChangeBoard

 public void ChangeBoard(ConsoleKey moveKey)
 {
     _snake.ChangeDirection(moveKey);
     _snake.MoveSnake ();
     _snake.CheckForCollision(_apple);
     ReplaceApple();
 }
开发者ID:Keruto,项目名称:INNLV,代码行数:7,代码来源:GameBoard.cs


示例4: GetCharFromConsoleKey

        internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modifiers)
        {
            // default for unprintables and unhandled
            char keyChar = '\u0000';

            // emulate GetKeyboardState bitmap - set high order bit for relevant modifier virtual keys
            var state = new byte[256];
            state[NativeMethods.VK_SHIFT] = (byte)(((modifiers & ConsoleModifiers.Shift) != 0) ? 0x80 : 0);
            state[NativeMethods.VK_CONTROL] = (byte)(((modifiers & ConsoleModifiers.Control) != 0) ? 0x80 : 0);
            state[NativeMethods.VK_ALT] = (byte)(((modifiers & ConsoleModifiers.Alt) != 0) ? 0x80 : 0);

            // a ConsoleKey enum's value is a virtual key code
            uint virtualKey = (uint)key;

            // get corresponding scan code
            uint scanCode = NativeMethods.MapVirtualKey(virtualKey, NativeMethods.MAPVK_VK_TO_VSC);

            // get corresponding character  - maybe be 0, 1 or 2 in length (diacriticals)
            var chars = new char[2];
            int charCount = NativeMethods.ToUnicode(
                virtualKey, scanCode, state, chars, chars.Length, NativeMethods.MENU_IS_INACTIVE);

            // TODO: support diacriticals (charCount == 2)
            if (charCount == 1)
            {
                keyChar = chars[0];
            }

            return keyChar;
        }
开发者ID:s-scherbinin-parc,项目名称:PSReadLine,代码行数:30,代码来源:ConsoleKeyChordConverter.cs


示例5: PlayGame

        static void PlayGame() {
            Dungeon dungeon = new Dungeon();
            player.X = dungeon.SpawnPoint[0];
            player.Y = dungeon.SpawnPoint[1];

            Cell currentRoom;
            ConsoleKey key = new ConsoleKey();
            do {
                IO.CleanConsole();
                //Console.WriteLine(player.X + ", " + player.Y);

                dungeon.Print(player);
                currentRoom = dungeon.Cells[player.X, player.Y];


                if (IO.PickUp(key)) {
                    player.Loot(currentRoom);
                }
                else {
                    if (currentRoom.HasItem) {
                        IO.PlayFoundItem();
                        currentRoom.Item.WriteFoundItem();
                    } else {
                        IO.PadLines(2);
                    }
                }

                key = Console.ReadKey().Key;

                player.Move(dungeon, key);

            } while (player.Health > 0);
        }
开发者ID:Sewil,项目名称:DungeonsOfDoom,代码行数:33,代码来源:Program.cs


示例6:

	internal ConsoleKeyInfo
				(char keyChar, ConsoleKey key, ConsoleModifiers modifiers)
			{
				this.keyChar = keyChar;
				this.key = key;
				this.modifiers = modifiers;
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:ConsoleKeyInfo.cs


示例7: Update

 public void Update(ConsoleKey key)
 {
     switch (key)
     {
         //This is grim. Needs a better method.
         case ConsoleKey.W:
             this._messenger.AddMessage("Up");
             Console.SetCursorPosition(this._player.PosX, this._player.PosY);
             this._map.map2[this._player.PosY, this._player.PosX].Draw();
             this._player.Move(Direction.Up);
             break;
         case ConsoleKey.A:
             this._messenger.AddMessage("Left");
             Console.SetCursorPosition(this._player.PosX, this._player.PosY);
             this._map.map2[this._player.PosY, this._player.PosX].Draw();
             this._player.Move(Direction.Left);
             break;
         case ConsoleKey.S:
             this._messenger.AddMessage("Down");
             Console.SetCursorPosition(this._player.PosX, this._player.PosY);
             this._map.map2[this._player.PosY, this._player.PosX].Draw();
             this._player.Move(Direction.Down);
             break;
         case ConsoleKey.D:
             this._messenger.AddMessage("Right");
             Console.SetCursorPosition(this._player.PosX, this._player.PosY);
             this._map.map2[this._player.PosY, this._player.PosX].Draw();
             this._player.Move(Direction.Right);
             break;
         default:
             break;
     }
 }
开发者ID:0x539,项目名称:RogueTest,代码行数:33,代码来源:GameManager.cs


示例8: GetDirection

		public static Point GetDirection(ConsoleKey _key)
		{
			if (!MoveKeys.Contains(_key))
			{
				return null;
			}

			var dx = (_key == ConsoleKey.LeftArrow ? -1 : 0) + (_key == ConsoleKey.RightArrow ? 1 : 0);
			var dy = (_key == ConsoleKey.UpArrow ? -1 : 0) + (_key == ConsoleKey.DownArrow ? 1 : 0);

			dx += (_key == ConsoleKey.NumPad4 ? -1 : 0) + (_key == ConsoleKey.NumPad6 ? 1 : 0);

			dx += (_key == ConsoleKey.NumPad7 ? -1 : 0) + (_key == ConsoleKey.NumPad9 ? 1 : 0);
			dx += (_key == ConsoleKey.NumPad1 ? -1 : 0) + (_key == ConsoleKey.NumPad3 ? 1 : 0);

			dx += (_key == ConsoleKey.Home ? -1 : 0) + (_key == ConsoleKey.PageUp ? 1 : 0);
			dx += (_key == ConsoleKey.End ? -1 : 0) + (_key == ConsoleKey.PageDown ? 1 : 0);

			dy += (_key == ConsoleKey.NumPad8 ? -1 : 0) + (_key == ConsoleKey.NumPad2 ? 1 : 0);

			dy += (_key == ConsoleKey.NumPad7 ? -1 : 0) + (_key == ConsoleKey.NumPad1 ? 1 : 0);
			dy += (_key == ConsoleKey.NumPad9 ? -1 : 0) + (_key == ConsoleKey.NumPad3 ? 1 : 0);

			dy += (_key == ConsoleKey.Home ? -1 : 0) + (_key == ConsoleKey.End ? 1 : 0);
			dy += (_key == ConsoleKey.PageUp ? -1 : 0) + (_key == ConsoleKey.PageDown ? 1 : 0);

			return new Point(dx, dy);
		}
开发者ID:Foxbow74,项目名称:my-busycator,代码行数:28,代码来源:KeyTranslator.cs


示例9: Move

        public void Move(ConsoleKey direction)
        {
            this.Clear();

            switch (direction)
            {
                case ConsoleKey.RightArrow:
                case ConsoleKey.D:
                    if (this.X < Console.WindowWidth - 4)
                    {
                        this.X++;
                    }

                    break;
                case ConsoleKey.LeftArrow:
                case ConsoleKey.A:
                    if (this.X > 0)
                    {
                        this.X--;
                    }

                    break;
            }

            this.Print();
        }
开发者ID:krasi070,项目名称:FallingRocks,代码行数:26,代码来源:Dwarf.cs


示例10: Trigger

 static void Trigger(ConsoleKey key)
 {
     if (key == ConsoleKey.X)
         HandleX(null, ConsoleKey.X);
     if (key == ConsoleKey.Spacebar)
         HandleSpace(null, ConsoleKey.Spacebar);
 }
开发者ID:g-yonchev,项目名称:TelerikAcademy_2015_2016,代码行数:7,代码来源:Events.cs


示例11: ConsoleKeyInfo

		public ConsoleKeyInfo (char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
		{
			_key = key;
			_keyChar = keyChar;
			_mods = 0;
			SetModifiers (shift, alt, control);
		}
开发者ID:jack-pappas,项目名称:mono,代码行数:7,代码来源:ConsoleKeyInfo.cs


示例12: CaptureKeyPressed

 static void CaptureKeyPressed(ConsoleKey key)
 {
     if (key == ConsoleKey.Enter)
     {
         HandleEnter(null, ConsoleKey.Enter);
     }
 }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:7,代码来源:Program.cs


示例13: PushUnmanaged

        public Subscription PushUnmanaged(ConsoleKey key, ConsoleModifiers? modifier, Action<ConsoleKeyInfo> handler)
        {
            Dictionary<ConsoleKey, Stack<Action<ConsoleKeyInfo>>> target;

            if (modifier.HasValue == false) target = nakedHandlers;
            else if (modifier.Value.HasFlag(ConsoleModifiers.Alt)) target = altHandlers;
            else if (modifier.Value.HasFlag(ConsoleModifiers.Shift)) target = shiftHandlers;
            else if (modifier.Value.HasFlag(ConsoleModifiers.Control)) target = controlHandlers;
            else throw new ArgumentException("Unsupported modifier: "+modifier.Value);

            Stack<Action<ConsoleKeyInfo>> targetStack;
            if(target.TryGetValue(key, out targetStack) == false)
            {
                targetStack = new Stack<Action<ConsoleKeyInfo>>();
                target.Add(key, targetStack);
            }

            targetStack.Push(handler);
            var sub = new Subscription(() =>
            {
                targetStack.Pop();
                if(targetStack.Count == 0)
                {
                    target.Remove(key);
                }
            });
            return sub;
        }
开发者ID:adamabdelhamed,项目名称:PowerArgs,代码行数:28,代码来源:KeyboardInterceptionManager.cs


示例14: SpecialInputs

        protected override Object SpecialInputs(ConsoleKey cki, EDirection currentDirection, EGameState gameState) {
            switch (cki) {
                case ConsoleKey.Escape:
                    if (gameState == EGameState.Running)
                        return gameState == EGameState.Running ? EGameState.Over : EGameState.Running;
                    if (gameState == EGameState.Over || gameState == EGameState.Init)
                        Environment.Exit(0);
                    break;
                case ConsoleKey.Spacebar:
                    return gameState == EGameState.Running ? EGameState.Paused : EGameState.Running;
                case ConsoleKey.Q:
                    if (gameState == EGameState.Init)
                        Environment.Exit(0);
                    if (gameState == EGameState.Over)
                        StartupManager.Reset();
                    break;
                case ConsoleKey.P:
                    if (gameState == EGameState.Init)
                        return EGameState.Running;
                    break;
            }

            if (cki == ConsoleKey.UpArrow && currentDirection != EDirection.South)
                return EDirection.North;
            if (cki == ConsoleKey.RightArrow && currentDirection != EDirection.West)
                return EDirection.East;
            if (cki == ConsoleKey.DownArrow && currentDirection != EDirection.North)
                return EDirection.South;
            if (cki == ConsoleKey.LeftArrow && currentDirection != EDirection.East)
                return EDirection.West;
            return cki;
        }
开发者ID:mikand13,项目名称:school_portfolio,代码行数:32,代码来源:SnakeInput.cs


示例15: MenuItem

 public MenuItem(Sub method,
                string description)
 {
     this.Method = method;
      this.Description = description;
      this.Key = ConsoleKey.NoName;
 }
开发者ID:wencywww,项目名称:Visual-Studio-2012,代码行数:7,代码来源:MenuItem.cs


示例16: Main

        static void Main(string[] args)
        {
            int curX, curY;
            //CursorVisible = false;
            curX = 10; //Starting positions
            curY = 10; //Starting positions

            spawnFood(curX, curY);
            SetCursorPosition(0, 0);
            Write(new string(snake, 4));

            ConsoleKey up = ConsoleKey.UpArrow;
            ConsoleKey down = ConsoleKey.DownArrow;
            ConsoleKey left = ConsoleKey.LeftArrow;
            ConsoleKey right = ConsoleKey.RightArrow;

            ConsoleKeyInfo cki;
            while (true)
            {
                cki = Console.ReadKey();
                if (cki.Key == up ||
                    cki.Key == right ||
                    cki.Key == down ||
                    cki.Key == left) direction = cki.Key;
                    
            }

            ReadKey();

        }
开发者ID:septIO,项目名称:Projects,代码行数:30,代码来源:Program.cs


示例17: AddKey

        static void AddKey(ConsoleKey key, ConsoleModifiers mod)
        {
            if ((int)mod != 0)

                Console.Write(mod.ToString() + " + ");
                //Console.WriteLine(key);
        }
开发者ID:seven2966,项目名称:data,代码行数:7,代码来源:Hook_Start.cs


示例18: HandelKey

 // Измененение направления змейки в соответствии с нажатиепм кнопки
 public void HandelKey(ConsoleKey key)
 {
     if (key == ConsoleKey.LeftArrow)
     {
         if (direction != Direction.RIGHT)
         {
             setDirection(Direction.LEFT);
         }
     }
     else if (key == ConsoleKey.RightArrow)
     {
         if (direction != Direction.RIGHT)
         {
             setDirection(Direction.RIGHT);
         }
     }
     else if (key == ConsoleKey.DownArrow)
     {
         if (direction != Direction.UP)
         {
             setDirection(Direction.DOWN);
         }
     }
     else if (key == ConsoleKey.UpArrow)
     {
         if (direction != Direction.DOWN)
         {
             setDirection(Direction.UP);
         }
     }
 }
开发者ID:bukan87,项目名称:snake,代码行数:32,代码来源:Snake.cs


示例19: KeysPressed

		public override void KeysPressed(ConsoleKey _key, EKeyModifiers _modifiers)
		{
			if (_modifiers != EKeyModifiers.NONE) return;
			switch (_key)
			{
				case ConsoleKey.Escape:
				case ConsoleKey.Z:
					CloseTopBlock();
					return;
				case ConsoleKey.V:
					MessageManager.SendMessage(this, new OpenUIBlockMessage(new BackpackUiBlock(Rct)));
					return;
			}
			var presenter = m_presenters.SingleOrDefault(_presenter => _presenter.Key == _key);

			if (presenter != null)
			{
				if (presenter.Item == null)
				{
					MessageManager.SendMessage(this, new OpenUIBlockMessage(new SelectToTakeOnUiBlock(Rct, this, presenter)));
				}
				else
				{
					Intelligent.TakeOff(presenter.Place);
					Rebuild();
				}
			}
		}
开发者ID:Foxbow74,项目名称:my-busycator,代码行数:28,代码来源:EquipmentUiBlock.cs


示例20: OnKeyPressed

		public override void OnKeyPressed(ConsoleKey key)
		{
			switch (key)
			{
				case ConsoleKey.F8:
					Console.BackgroundColor = ColorTheme.TextBoxBackgroundColor;
					Console.ForegroundColor = ColorTheme.TextBoxForegroundColor;
					Console.SetCursorPosition(_left, _height + _top - 4);
					for (int i = 0; i < 4; i++)
						ConsoleHelper.WriteToEnd(_width);
					EndDraw();
					Console.SetCursorPosition(_left, _height + _top - 4);
					Console.CursorVisible = true;
					Console.Write("Введите путь к файлу лицензии: ");
					var path = Console.ReadLine();
					Console.CursorVisible = false;
					var error = LicensePresenter.LoadLicense(path);
					if (!String.IsNullOrEmpty(error))
					{
						Console.SetCursorPosition(_left, _height + _top - 4);
						for (int i = 0; i < 4; i++)
							ConsoleHelper.WriteToEnd(_width);
						Console.SetCursorPosition(_left, _height + _top - 4);
						Console.Write(error);
						EndDraw();
						Console.ReadKey();
					}
					Draw(_left, _top, _width, _height);
					break;
			}
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:31,代码来源:LicensePage.cs



注:本文中的ConsoleKey类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ConsoleLogger类代码示例发布时间:2022-05-24
下一篇:
C# ConsoleColor类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap