Exemplo n.º 1
0
        public void ProcessKeyInput(double deltaTime)
        {
            var pressedKeys = appender.Input.GetPressedKeys();

            bool isShiftPressed = appender.Input.IsKeyPressed(Keys.LeftShift) ||
                                  appender.Input.IsKeyPressed(Keys.RightShift);


            foreach (Keys key in pressedKeys)
            {
                if (!ShouldHandleKey(key, deltaTime))
                {
                    continue;
                }

                char convertedChar;
                if (KeyboardUtils.KeyToString(key, isShiftPressed, out convertedChar))
                {
                    if (!appender.ShouldHandleKey(key, convertedChar))
                    {
                        continue;
                    }
                    KeyPressed.RaiseEvent(this, convertedChar);
                }
                else
                {
                    switch (key)
                    {
                    case Keys.Back:
                        BackSpace.RaiseEvent(this, EventArgs.Empty);
                        break;

                    case Keys.Delete:
                        Delete.RaiseEvent(this, EventArgs.Empty);
                        break;

                    case Keys.Left:
                        Left.RaiseEvent(this, EventArgs.Empty);
                        break;

                    case Keys.Right:
                        Right.RaiseEvent(this, EventArgs.Empty);
                        break;

                    case Keys.Up:
                        Up.RaiseEvent(this, EventArgs.Empty);
                        break;

                    case Keys.Down:
                        Down.RaiseEvent(this, EventArgs.Empty);
                        break;

                    case Keys.Enter:
                        Insert.RaiseEvent(this, EventArgs.Empty);
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Trim beginning backspaces, if any. Return number trimmed.
        /// </summary>
        private int TrimBeginningBackspaces(ref string text)
        {
            const char BackSpace = '\b';             // 0x0008

            if (!text.StartsWith(BackSpace.ToString()))
            {
                return(0);
            }

            int count = text.Length - text.TrimStart(BackSpace).Length;

            text = text.TrimStart(BackSpace);
            return(count);
        }
Exemplo n.º 3
0
        void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar >= 40 && e.KeyChar <= 57)
            {
                //MessageBox.Show("Form.KeyPress: " +
                //e.KeyChar.ToString() + e.KeyChar);

                switch (e.KeyChar)
                {
                case (char)40:
                    openbracket.PerformClick();
                    break;

                case (char)41:
                    closebracket.PerformClick();
                    break;

                case (char)42:
                    mulitply.PerformClick();
                    break;

                case (char)43:
                    plus.PerformClick();
                    break;

                case (char)45:
                    minus.PerformClick();
                    break;

                case (char)46:
                    button_dp.PerformClick();
                    break;

                case (char)47:
                    divide.PerformClick();
                    break;

                case (char)48:
                    button0.PerformClick();
                    break;

                case (char)49:
                    button1.PerformClick();
                    break;

                case (char)50:
                    button2.PerformClick();
                    break;

                case (char)51:
                    button3.PerformClick();
                    break;

                case (char)52:
                    button4.PerformClick();
                    break;

                case (char)53:
                    button5.PerformClick();
                    break;

                case (char)54:
                    button6.PerformClick();
                    break;

                case (char)55:
                    button7.PerformClick();
                    break;

                case (char)56:
                    button8.PerformClick();
                    break;

                case (char)57:
                    button9.PerformClick();
                    break;
                }
            }
            if (e.KeyChar == 8)
            {
                BackSpace.PerformClick();
            }
            if (e.KeyChar == 61 || e.KeyChar == 13)
            {
                answer.PerformClick();
            }
            //if (e.KeyChar == 94)
            //    power.PerformClick();
            //Ctrl C
            //if (e.KeyChar == 3)
            //System.Windows.Forms.Clipboard.SetText(TextResult.Text);
            //ctrl V
            //if (e.KeyChar == 22)
            //{
            //check if paste will be decimal
            //PasteText = System.Windows.Forms.Clipboard.GetText();
            //decimal PasteCheck;
            //if (Decimal.TryParse(PasteText, out PasteCheck))
            //{
            //    TextResult.Text = PasteText;
            //    MemRecall1 = true;
            // }
            //}
            //ctrl X
            //if (e.KeyChar == 24)
            //{
            //  System.Windows.Forms.Clipboard.SetText(TextResult.Text);
            //TextResult.Text = "0";
            // }
            e.Handled = true;
            ErrorLabel.Focus();
        }