Example #1
0
        /// <summary>
        /// check if key string match keyData representing key pressed code</summary>
        public static bool ParseKey(string key, Keys keyData)
        {
            string[] parts   = key.Split('+');
            Keys     keyCode = 0;
            Keys     code    = 0;

            foreach (string part in parts)
            {
                if (part == "CTRL")
                {
                    keyCode = Keys.Control | keyCode;
                    continue;
                }

                if (part == "ALT")
                {
                    keyCode = Keys.Alt | keyCode;
                    continue;
                }

                if (part == "SHIFT")
                {
                    keyCode = Keys.Shift | keyCode;
                    continue;
                }

                if (part == "PAGEUP")
                {
                    keyCode = Keys.PageUp | keyCode;
                    continue;
                }

                if (part == "PAGEDOWN")
                {
                    keyCode = Keys.PageDown | keyCode;
                    continue;
                }

                if (part == "INS")
                {
                    keyCode = Keys.Insert | keyCode;
                    continue;
                }

                if (part == "DEL")
                {
                    keyCode = Keys.Delete | keyCode;
                    continue;
                }

                if (part == "LEFT")
                {
                    keyCode = Keys.Left | keyCode;
                    continue;
                }

                if (part == "RIGHT")
                {
                    keyCode = Keys.Right | keyCode;
                    continue;
                }

                if (part == "UP")
                {
                    keyCode = Keys.Up | keyCode;
                    continue;
                }

                if (part == "DOWN")
                {
                    keyCode = Keys.Down | keyCode;
                    continue;
                }

                if (part == "0")
                {
                    keyCode = Keys.D0 | keyCode;
                    continue;
                }

                if (part == "1")
                {
                    keyCode = Keys.D1 | keyCode;
                    continue;
                }

                if (part == "2")
                {
                    keyCode = Keys.D2 | keyCode;
                    continue;
                }

                if (part == "3")
                {
                    keyCode = Keys.D3 | keyCode;
                    continue;
                }

                if (part == "4")
                {
                    keyCode = Keys.D4 | keyCode;
                    continue;
                }

                if (part == "5")
                {
                    keyCode = Keys.D5 | keyCode;
                    continue;
                }

                if (part == "6")
                {
                    keyCode = Keys.D6 | keyCode;
                    continue;
                }

                if (part == "7")
                {
                    keyCode = Keys.D7 | keyCode;
                    continue;
                }

                if (part == "8")
                {
                    keyCode = Keys.D8 | keyCode;
                    continue;
                }

                if (part == "9")
                {
                    keyCode = Keys.D9 | keyCode;
                    continue;
                }

                if (Enum.TryParse(Fonts.FirstCharToUpper(part), out code))
                {
                    keyCode = code | keyCode;
                }
            }

            if (keyCode == keyData)
            {
                return(true);
            }

            return(false);
        }