Exemplo n.º 1
0
        static public string ValidateKeyTextBoxMsg(Form frmCaller, KB9TextBox ctrlText)
        {
            if (ctrlText == null)
            {
                return("");
            }
            string strKeys = ctrlText.Text;// GetInputedKeyCodes();

            if (strKeys == string.Empty)
            {
                return("");
            }
            KB9Validation kb9 = new KB9Validation();

            KB9Validation.ERR_VALIDATION err = kb9.ValidateKB9Keycodes(strKeys);
            if (err == KB9Validation.ERR_VALIDATION.OK)
            {
                return("");
            }

            string err_msg = ValidateErrMsg(err);

            return(err_msg);

            //if (err == KB9Validation.ERR_VALIDATION.Less_AltUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_RAltUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_CtrlUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_RCtrlUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_RShiftUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_ShiftUp)
            //{

            //    return err_msg;
            //    //err_msg += "\n\rDo you want utility append this key to end?";

            //    //DialogResult result = MessageBox.Show(frmCaller, err_msg, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
            //    //if (result == DialogResult.Yes)
            //    //{
            //    //    string strAppend = AppendErrKey(err);
            //    //    ctrlText.AddKeyCode(strAppend, false);
            //    //}
            //}
            //else
            //{
            //    err_msg += "\n\rPlease fixed it manually.";
            //    MessageBox.Show(frmCaller, err_msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}

            //return false;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Out all key code with []
        /// @bCapsEffect:
        ///         Whether the caps_lock_effect worked.
        ///
        /// </summary>
        /// <returns></returns>
        public string ToCSV(bool bCapsEffect)
        {
            string s = this.ToString();

            s = expand_combination(s);
            if (bCapsEffect)
            { //if caps effect enabled, append [ ] to this single character
                if (s.Length == 1)
                {
                    char ch = s[0];
                    //if (ch >= 'a' && ch <= 'z')
                    if (isEmulateKbdKey(ch)) //20141208
                    {
                        s = "[" + s + "]";
                    }
                }
                else if (s.Equals("\\["))
                {
                    s = "[{]";
                }
                else if (s.Equals("\\]"))
                {
                    s = "[}]";
                }
                else if (s.Equals("\\\\"))
                {
                    s = "[\\]";
                }
            }
            //20140203
            s = KB9Validation.auto_fix_key_content(s);
            s = convertPause(s);
            return(s);
            //List<string> lst = new List<string>();
            //int n = Util.ParseKeyContents(s, lst);
            //string strReturn = "";
            //for (int i=0; i< n; i++)
            //{
            //    s = lst[i];
            //    if (s == string.Empty)
            //        continue;
            //    if (!ExistBracket(s))
            //    {
            //        s = "[" + s + "]";
            //        lst[i] = s;
            //    }
            //    strReturn += lst[i];
            //}
            //return strReturn;
        }
Exemplo n.º 3
0
        static public bool ValidateKeyTextBox(Form frmCaller, KB9TextBox ctrlText)
        {
            string strKeys = ctrlText.Text;// GetInputedKeyCodes();

            if (strKeys == string.Empty)
            {
                return(true);
            }
            KB9Validation kb9 = new KB9Validation();

            KB9Validation.ERR_VALIDATION err = kb9.ValidateKB9Keycodes(strKeys);
            if (err == KB9Validation.ERR_VALIDATION.OK)
            {
                return(true);
            }

            string err_msg = ValidateErrMsg(err);

            if (err == KB9Validation.ERR_VALIDATION.Less_AltUp ||
                err == KB9Validation.ERR_VALIDATION.Less_RAltUp ||
                err == KB9Validation.ERR_VALIDATION.Less_CtrlUp ||
                err == KB9Validation.ERR_VALIDATION.Less_RCtrlUp ||
                err == KB9Validation.ERR_VALIDATION.Less_RShiftUp ||
                err == KB9Validation.ERR_VALIDATION.Less_ShiftUp ||
                err == KB9Validation.ERR_VALIDATION.Less_WinUp ||
                err == KB9Validation.ERR_VALIDATION.Less_RWinUp)
            {
                err_msg += "\n\rDo you want utility append this key to end?";

                DialogResult result = MessageBox.Show(frmCaller, err_msg, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (result == DialogResult.Yes)
                {
                    string strAppend = AppendErrKey(err);
                    ctrlText.AddKeyCode(strAppend, false);
                }
            }
            else
            {
                err_msg += "\n\rPlease fixed it manually.";
                MessageBox.Show(frmCaller, err_msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(false);
        }
Exemplo n.º 4
0
        private void txtMacro1_Validating(object sender, CancelEventArgs e)
        {
            KB9TextBox t = (KB9TextBox)sender;

            if (t == null)
            {
                return;
            }
            System.Diagnostics.Debug.Print("txtMacro1_Validating " + t.Name);
            int nres = KB9Validation.ValidateKeyTextBox2(this, t);

            if (nres == 0)
            {
                t.ClearUndo();
                return;
            }

            e.Cancel = true;

            if (nres == 3) //cancel changes
            {
                t.Undo();
            }
        }
Exemplo n.º 5
0
        private bool ValidateKeyTextBox(KB9TextBox ctrlText)
        {
            return(KB9Validation.ValidateKeyTextBox(this, ctrlText));
            //string strKeys = ctrlText.Text;// GetInputedKeyCodes();
            //if (strKeys == string.Empty) return true;
            //KB9Validation kb9 = new KB9Validation();
            //KB9Validation.ERR_VALIDATION err = kb9.ValidateKB9Keycodes(strKeys);
            //if (err == KB9Validation.ERR_VALIDATION.OK) return true;

            //string err_msg = ValidateErrMsg(err);
            //if (err == KB9Validation.ERR_VALIDATION.Less_AltUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_RAltUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_CtrlUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_RCtrlUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_RShiftUp ||
            //    err == KB9Validation.ERR_VALIDATION.Less_ShiftUp)
            //{


            //    err_msg += "\n\rDo you want utility append this key to end?";

            //    DialogResult result = MessageBox.Show(err_msg, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
            //    if (result == DialogResult.Yes)
            //    {
            //        string strAppend = AppendErrKey(err);
            //        ctrlText.AddKeyCode(strAppend, false);
            //    }
            //}
            //else
            //{
            //    err_msg += "\n\rPlease fixed it manually.";
            //    MessageBox.Show(err_msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}

            //return false;
        }
Exemplo n.º 6
0
        /************************************************************************/

        /*
         * check key code error
         */
        /************************************************************************/
        public DiagramKey ErrorKeyUp()
        {
            int           ncount  = m_objs.GetSize();
            KB9Validation checker = new KB9Validation();

            for (int i = 0; i < ncount; i++)
            {
                DiagramEntity entity = m_objs.GetAt(i);
                if (entity.TypeName == DiagramKey.KEY_BUTTON)
                {
                    DiagramKeyArea key  = (DiagramKeyArea)entity;
                    string         code = key.KeyCode.GetKeyCodeString();
                    if (checker.ValidateKB9Keycodes(code) != KB9Validation.ERR_VALIDATION.OK)
                    {
                        return(key);
                    }
                }
                else if (entity.TypeName == DiagramKey.KEY_SLIDEH)
                {
                    DiagramKeySlideH key = (DiagramKeySlideH)entity;

                    string slideLeft = key.SlideLeft.GetKeyCodeString();
                    if (checker.ValidateKB9Keycodes(slideLeft) != KB9Validation.ERR_VALIDATION.OK)
                    {
                        return(key);
                    }
                    string slideLeftHold = key.SlideLeftHold.GetKeyCodeString();
                    if (checker.ValidateKB9Keycodes(slideLeftHold) != KB9Validation.ERR_VALIDATION.OK)
                    {
                        return(key);
                    }
                    string slideRight = key.SlideRight.GetKeyCodeString();
                    if (checker.ValidateKB9Keycodes(slideRight) != KB9Validation.ERR_VALIDATION.OK)
                    {
                        return(key);
                    }
                    string slideRightHold = key.SlideRightHold.GetKeyCodeString();
                    if (checker.ValidateKB9Keycodes(slideRightHold) != KB9Validation.ERR_VALIDATION.OK)
                    {
                        return(key);
                    }
                }
                else if (entity.TypeName == DiagramKey.KEY_SLIDEV)
                {
                    DiagramKeySlideV key = (DiagramKeySlideV)entity;

                    string slideUp = key.SlideUp.GetKeyCodeString();
                    if (checker.ValidateKB9Keycodes(slideUp) != KB9Validation.ERR_VALIDATION.OK)
                    {
                        return(key);
                    }
                    string slideUpHold = key.SlideUpHold.GetKeyCodeString();
                    if (checker.ValidateKB9Keycodes(slideUpHold) != KB9Validation.ERR_VALIDATION.OK)
                    {
                        return(key);
                    }
                    string slideDown = key.SlideDown.GetKeyCodeString();
                    if (checker.ValidateKB9Keycodes(slideDown) != KB9Validation.ERR_VALIDATION.OK)
                    {
                        return(key);
                    }
                    string slideDownHold = key.SlideDownHold.GetKeyCodeString();
                    if (checker.ValidateKB9Keycodes(slideDownHold) != KB9Validation.ERR_VALIDATION.OK)
                    {
                        return(key);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 7
0
        /************************************************************************/

        /*
         * return: 0: ok
         *          1: messagebox shown, and correct
         *          2: messagebox shown, and manually correct them
         *          3: cancel edit, undo
         */
        /************************************************************************/
        static public int ValidateKeyTextBox2(Form frmCaller, KB9TextBox ctrlText)
        {
            string strKeys = ctrlText.Text;// GetInputedKeyCodes();

            if (strKeys == string.Empty)
            {
                return(0);
            }
            KB9Validation kb9 = new KB9Validation();

            KB9Validation.ERR_VALIDATION err = kb9.ValidateKB9Keycodes(strKeys);
            if (err == KB9Validation.ERR_VALIDATION.OK)
            {
                return(0);
            }
            string err_msg = ValidateErrMsg(err);
            string strlog  = "Key contents validation error";

            strlog += KB9Logger.LOG_LF;
            strlog += KB9Logger.LOG_TAB;
            strlog += ("Key contents:" + strKeys);
            strlog += KB9Logger.LOG_LF;
            strlog += KB9Logger.LOG_TAB;
            strlog += err_msg;

            KB9Logger.Err(strlog);



            if (err == KB9Validation.ERR_VALIDATION.Single_Function_With_Up)
            { //if it is single function key, just keep down key.
                ctrlText.RemoveLastKey();
                ctrlText.Refresh();
                return(0);
            }

            if (err == ERR_VALIDATION.Repeat_Must_Follow_Key ||
                err == ERR_VALIDATION.Repeat_Can_Not_Follow_Combination_Macro_Pause)
            {
                MessageBox.Show(frmCaller,
                                err_msg,
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return(2);
            }

            if (err == ERR_VALIDATION.Less_AltDown ||
                err == ERR_VALIDATION.Less_CtrlDown ||
                err == ERR_VALIDATION.Less_RAltDown ||
                err == ERR_VALIDATION.Less_RCtrlDown ||
                err == ERR_VALIDATION.Less_RShiftDown ||
                err == ERR_VALIDATION.Less_RWinDown ||
                err == ERR_VALIDATION.Less_ShiftDown ||
                err == ERR_VALIDATION.Less_WinDown)
            {
                DialogResult r = frmKeyCodeLessDown.ConfirmCancel();// MessageBox.Show(frmCaller,
                if (r == DialogResult.Yes)
                {
                    return(3);
                }
                else
                {
                    return(2);
                }
            }

            //DialogResult result = MessageBox.Show(frmCaller,
            //                                      "Key release codes does not match with corresponding key press codes.  Automatic fix by inserting key release codes at the end?",
            //                                      "Warning",
            //                                      MessageBoxButtons.YesNo,
            //                                      MessageBoxIcon.Warning);
            DialogResult result = frmKeyCodeError.ConfirmError();// MessageBox.Show(frmCaller,

            if (result == DialogResult.Yes)
            {
                int nloop = 0;
                while (err != ERR_VALIDATION.OK)
                {
                    if (err == KB9Validation.ERR_VALIDATION.Less_AltUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_RAltUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_CtrlUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_RCtrlUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_RShiftUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_ShiftUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_WinUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_RWinUp)
                    {
                        string strAppend = AppendErrKey(err);
                        //ctrlText.AddKeyCode(strAppend, false);
                        ctrlText.AppendKeyCode(strAppend);
                    }
                    //else if (err == KB9Validation.ERR_VALIDATION.Single_Function_With_Up)
                    //{
                    //    ctrlText.RemoveLastKey();
                    //}
                    else
                    { //less down, remove last up
                        string strRemove = RemoveErrKey(err);
                        ctrlText.RemoveLastKeyCode(strRemove);
                    }
                    strKeys = ctrlText.Text;
                    err     = kb9.ValidateKB9Keycodes(strKeys);
                    nloop++;
                    if (nloop > 256)
                    {
                        MessageBox.Show(frmCaller, "The automatic fix failed, please correct it manually.",
                                        "Warning",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                        ctrlText.Refresh();
                        //log
                        strlog  = "Can not fixed automaticly.";
                        strlog += KB9Logger.LOG_LF;
                        strlog += KB9Logger.LOG_TAB;
                        strlog += "Result:";
                        strlog += ctrlText.Text;
                        KB9Logger.Err(strlog);
                        return(2);
                    }
                }
                ctrlText.Refresh();
                //log
                strKeys = ctrlText.Text;
                strlog  = "Auto fixed result:";
                strlog += KB9Logger.LOG_LF;
                strlog += KB9Logger.LOG_TAB;
                strlog += strKeys;
                KB9Logger.Log(strlog);
            }
            else
            {
                return(2);
            }



            return(1);
        }