Ejemplo n.º 1
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.º 2
0
        /// <summary>
        /// Gets the key pressed.
        /// </summary>
        /// <returns></returns>
        public Key GetKeyPressed()
        {
            byte scanCode = keyboardDevice.GetScanCode();

            if (scanCode == 0)
            {
                return(null);
            }

            var keyEvent = scanCodeMap.ConvertScanCode(scanCode);

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

            if (keyEvent.KeyType == KeyType.CapsLock)
            {
                CapLock = (keyEvent.KeyPress == KeyEvent.KeyPressType.Make);
            }
            else if (keyEvent.KeyType == KeyType.NumLock)
            {
                NumLock = (keyEvent.KeyPress == KeyEvent.KeyPressType.Make);
            }
            else if (keyEvent.KeyType == KeyType.ScrollLock)
            {
                ScrollLock = (keyEvent.KeyPress == KeyEvent.KeyPressType.Make);
            }
            else if (keyEvent.KeyType == KeyType.LeftControl)
            {
                LeftControl = (keyEvent.KeyPress == KeyEvent.KeyPressType.Make);
            }
            else if (keyEvent.KeyType == KeyType.RightControl)
            {
                RightControl = (keyEvent.KeyPress == KeyEvent.KeyPressType.Make);
            }
            else if (keyEvent.KeyType == KeyType.LeftAlt)
            {
                LeftAlt = (keyEvent.KeyPress == KeyEvent.KeyPressType.Make);
            }
            else if (keyEvent.KeyType == KeyType.RightAlt)
            {
                RightAlt = (keyEvent.KeyPress == KeyEvent.KeyPressType.Make);
            }
            else if (keyEvent.KeyType == KeyType.LeftShift)
            {
                LeftShift = (keyEvent.KeyPress == KeyEvent.KeyPressType.Make);
            }
            else if (keyEvent.KeyType == KeyType.RightShift)
            {
                RightShift = (keyEvent.KeyPress == KeyEvent.KeyPressType.Make);
            }

            return(null);
        }