Implements a key
Ejemplo n.º 1
0
        /// <summary>
        /// Gets the key pressed.
        /// </summary>
        /// <returns></returns>
        public Key GetKeyPressed_OLD()
        {
            Key key = new Key();

            ConsoleKeyInfo keyInfo = Console.ReadKey(true);

            key.Character = keyInfo.KeyChar;
            key.Alt = (keyInfo.Modifiers & ConsoleModifiers.Alt) == ConsoleModifiers.Alt;
            key.Control = (keyInfo.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control;
            key.Shift = (keyInfo.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift;

            key.KeyType = KeyType.RegularKey;

            switch (keyInfo.Key) {
                case ConsoleKey.Home: key.KeyType = KeyType.Home; break;
                case ConsoleKey.UpArrow: key.KeyType = KeyType.UpArrow; break;
                case ConsoleKey.PageUp: key.KeyType = KeyType.PageUp; break;
                case ConsoleKey.LeftArrow: key.KeyType = KeyType.LeftArrow; break;
                case ConsoleKey.RightArrow: key.KeyType = KeyType.RightArrow; break;
                case ConsoleKey.End: key.KeyType = KeyType.End; break;
                case ConsoleKey.DownArrow: key.KeyType = KeyType.DownArrow; break;
                case ConsoleKey.PageDown: key.KeyType = KeyType.PageDown; break;
                case ConsoleKey.Insert: key.KeyType = KeyType.Insert; break;
                case ConsoleKey.Delete: key.KeyType = KeyType.Delete; break;
                case ConsoleKey.F1: key.KeyType = KeyType.F1; break;
                case ConsoleKey.F2: key.KeyType = KeyType.F2; break;
                case ConsoleKey.F3: key.KeyType = KeyType.F3; break;
                case ConsoleKey.F4: key.KeyType = KeyType.F4; break;
                case ConsoleKey.F5: key.KeyType = KeyType.F5; break;
                case ConsoleKey.F6: key.KeyType = KeyType.F6; break;
                case ConsoleKey.F7: key.KeyType = KeyType.F7; break;
                case ConsoleKey.F8: key.KeyType = KeyType.F8; break;
                case ConsoleKey.F9: key.KeyType = KeyType.F9; break;
                case ConsoleKey.F10: key.KeyType = KeyType.F10; break;
                case ConsoleKey.F11: key.KeyType = KeyType.F11; break;
                case ConsoleKey.F12: key.KeyType = KeyType.F12; break;
                case ConsoleKey.LeftWindows: key.KeyType = KeyType.LeftWindow; break;
                case ConsoleKey.RightWindows: key.KeyType = KeyType.RightWindow; break;
                case ConsoleKey.Sleep: key.KeyType = KeyType.Sleep; break;
                case ConsoleKey.PrintScreen: key.KeyType = KeyType.PrintScreen; break;
                default: break;
            }

            return key;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the key pressed.
        /// </summary>
        /// <returns></returns>
        public Key GetKeyPressed()
        {
            for (; ; )
            {
                byte scanCode = keyboardDevice.GetScanCode();

                KeyEvent keyEvent = scanCodeMap.ConvertScanCode(scanCode);

                if (keyEvent.KeyType == KeyType.RegularKey)
                {
                    if (keyEvent.KeyPress == KeyEvent.Press.Make)
                    {
                        Key key = new Key();
                        key.KeyType = KeyType.RegularKey;
                        key.Character = keyEvent.Character;
                        key.Alt = Alt;
                        key.Control = Control;
                        key.Shift = Shift;
                        return key;
                    }
                }

                if (keyEvent.KeyType == KeyType.CapsLock)
                    capLock = (keyEvent.KeyPress == KeyEvent.Press.Make);

                if (keyEvent.KeyType == KeyType.NumLock)
                    numLock = (keyEvent.KeyPress == KeyEvent.Press.Make);

                if (keyEvent.KeyType == KeyType.ScrollLock)
                    scrollLock = (keyEvent.KeyPress == KeyEvent.Press.Make);

                if (keyEvent.KeyType == KeyType.LeftControl)
                    leftControl = (keyEvent.KeyPress == KeyEvent.Press.Make);

                if (keyEvent.KeyType == KeyType.RightControl)
                    rightControl = (keyEvent.KeyPress == KeyEvent.Press.Make);

                if (keyEvent.KeyType == KeyType.LeftAlt)
                    leftAlt = (keyEvent.KeyPress == KeyEvent.Press.Make);

                if (keyEvent.KeyType == KeyType.RightAlt)
                    rightAlt = (keyEvent.KeyPress == KeyEvent.Press.Make);

                if (keyEvent.KeyType == KeyType.LeftShift)
                    leftShift = (keyEvent.KeyPress == KeyEvent.Press.Make);

                if (keyEvent.KeyType == KeyType.RightShift)
                    rightShift = (keyEvent.KeyPress == KeyEvent.Press.Make);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Accepts the key.
 /// </summary>
 /// <param name="key">The key.</param>
 public void AcceptKey(Key key)
 {
     keys.Enqueue(key);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the key pressed.
        /// </summary>
        /// <returns></returns>
        public Key GetKeyPressed()
        {
            for (; ;)
            {
                byte scanCode = keyboardDevice.GetScanCode();

                KeyEvent keyEvent = scanCodeMap.ConvertScanCode(scanCode);

                if (keyEvent.KeyType == KeyType.RegularKey)
                {
                    if (keyEvent.KeyPress == KeyEvent.Press.Make)
                    {
                        Key key = new Key();
                        key.KeyType   = KeyType.RegularKey;
                        key.Character = keyEvent.Character;
                        key.Alt       = Alt;
                        key.Control   = Control;
                        key.Shift     = Shift;
                        return(key);
                    }
                }

                if (keyEvent.KeyType == KeyType.CapsLock)
                {
                    capLock = (keyEvent.KeyPress == KeyEvent.Press.Make);
                }

                if (keyEvent.KeyType == KeyType.NumLock)
                {
                    numLock = (keyEvent.KeyPress == KeyEvent.Press.Make);
                }

                if (keyEvent.KeyType == KeyType.ScrollLock)
                {
                    scrollLock = (keyEvent.KeyPress == KeyEvent.Press.Make);
                }

                if (keyEvent.KeyType == KeyType.LeftControl)
                {
                    leftControl = (keyEvent.KeyPress == KeyEvent.Press.Make);
                }

                if (keyEvent.KeyType == KeyType.RightControl)
                {
                    rightControl = (keyEvent.KeyPress == KeyEvent.Press.Make);
                }

                if (keyEvent.KeyType == KeyType.LeftAlt)
                {
                    leftAlt = (keyEvent.KeyPress == KeyEvent.Press.Make);
                }

                if (keyEvent.KeyType == KeyType.RightAlt)
                {
                    rightAlt = (keyEvent.KeyPress == KeyEvent.Press.Make);
                }

                if (keyEvent.KeyType == KeyType.LeftShift)
                {
                    leftShift = (keyEvent.KeyPress == KeyEvent.Press.Make);
                }

                if (keyEvent.KeyType == KeyType.RightShift)
                {
                    rightShift = (keyEvent.KeyPress == KeyEvent.Press.Make);
                }
            }
        }