private void Bt_Power_Click(object sender, RoutedEventArgs e)
        {
            Window_Shutdown_PowerOff Shutdown_PowerOff = new Window_Shutdown_PowerOff();
            Shutdown_PowerOff.Show();
            this.Close();//关闭当前窗口 

        }
        public void keyboardInfoProce(string type, string value)
        {
            //  返回值类型为 null,不做任何改变(保持焦点不变) 。 结束调用此次事件处理函数

            if (type == "null")
            {
                focusUnchanged();
                return;
            }

            else if (type == "number" || type == "character" || type == "symbol")
            {
                //  返回值类型为 数字(number) 字母(character) 字符(other)  直接调用插入函数
                for (int i = 0; i < TB.Length; i++)
                {
                    if (getIsTBFocused(TB[i].Name))
                    {
                        tbstringfun(TB[i], 0, value);
                    }
                }
                return;
            }

            else if (type == "character_replace")
            {
                for (int i = 0; i < TB.Length; i++)
                {
                    if (getIsTBFocused(TB[i].Name))
                    {
                        tbstringfun(TB[i], 1, value);
                    }
                }
                return;
            }

            //  返回值类型为 功能键(function)
            else if (type == "function")
            {
                switch (value)
                {
                    case "Soft":
                        #region "显示软键盘"
                        toggleSoftKeyboard();
                        //   MessageBox.Show("显示软件盘");
                        break;
                        #endregion

                    case "Starkey":
                        //  MessageBox.Show("快捷键");
                        break;

                    case "Power":
                        #region  "关机界面"
                        Window_Shutdown_PowerOff Shutdown_PowerOff = new Window_Shutdown_PowerOff();
                        Shutdown_PowerOff.Show();
                        this.Close();//关闭当前窗口 
                        break;
                        #endregion

                    case "Func":
                        // MessageBox.Show("Func");
                        break;

                    case "Ctrl":
                        break;

                    case "Alt":
                        break;

                    case "Del":
                        #region "删除字符"
                        for (int i = 0; i < TB.Length; i++)
                        {
                            if (getIsTBFocused(TB[i].Name))
                            {
                                tbstringfun(TB[i], 3, "*");
                            }
                        }
                        break;
                        #endregion

                    case "Tab":
                        #region  "切换焦点"
                        txtfocus = (txtfocus + 1) % (TB.Length);
                        TB[txtfocus].Focus();
                        break;
                        #endregion

                    case "B.S":
                        #region "删除字符"
                        for (int i = 0; i < TB.Length; i++)
                        {
                            if (getIsTBFocused(TB[i].Name))
                            {
                                tbstringfun(TB[i], 2, "*");
                            }
                        }
                        break;
                        #endregion

                    case "ESC":
                        #region "返回上一界面"
                        ESC_Click();
                        break;
                        #endregion

                    case "ENT":
                        #region "确认"
                        ENT_Click();
                        break;
                        #endregion

                    case "Dn":
                        #region "切换焦点"
                        txtfocus = (txtfocus + 1) % (TB.Length);
                        TB[txtfocus].Focus();
                        break;
                        #endregion

                    case "Up":
                        #region "切换焦点"
                        if (txtfocus - 1 < 0)
                        {
                            txtfocus = TB.Length - 1;
                        }
                        else
                        {
                            txtfocus = (txtfocus - 1) % (TB.Length);
                        }

                        TB[txtfocus].Focus();
                        break;
                        #endregion

                    case "Lt":
                        #region "移动光标"
                        for (int i = 0; i < TB.Length; i++)
                        {
                            if (getIsTBFocused(TB[i].Name))
                            {
                                selectPos = TB[i].SelectionStart;
                                TB[i].Focus();
                                if (selectPos >= 1)
                                {
                                    TB[i].Select(selectPos - 1, 0);
                                }
                            }
                        }
                        break;
                        #endregion

                    case "Rt":
                        #region "移动光标"
                        for (int i = 0; i < TB.Length; i++)
                        {
                            if (getIsTBFocused(TB[i].Name))
                            {
                                selectPos = TB[i].SelectionStart;
                                TB[i].Focus();
                                if (selectPos < this.TB[i].Text.Length)
                                {
                                    TB[i].Select(selectPos + 1, 0);
                                }
                            }
                        }
                        break;
                        #endregion

                    default:
                        #region
                        focusUnchanged();

                        break;
                        #endregion
                }
            }
            else
            {
                //  返回值为其他键 不做任何改变(焦点保持不变)
                focusUnchanged();
            }
            return;
        }
        private void LayoutRoot_Click(object sender, RoutedEventArgs e)
        {
            Button bt = e.OriginalSource as Button;
            if (bt != null)
            {

                string keyName = bt.Name.ToString();
                switch (keyName)
                {
                    case "Arfakey":
                        #region case "Arfakey":
                        if (isupper)
                        {
                            isupper = false;
                            myMessageBox my = new myMessageBox();
                            my.show("小写字母");
                            //MessageBox.Show("小写字母");
                        }
                        else
                        {
                            isupper = true;
                            myMessageBox my = new myMessageBox();
                            my.show("大写字母");
                            //MessageBox.Show("大写字母");
                        }
                        break;
                        #endregion
                    case "Softkey":
                        //   MessageBox.Show("显示软件盘");
                        break;
                    case "Starkey":
                        //  MessageBox.Show("快捷键");
                        break;
                    case "Powerkey":
                        #region
                         Window_Shutdown_PowerOff Shutdown_PowerOff = new Window_Shutdown_PowerOff();
                         Shutdown_PowerOff.Show();
                         this.Close();//关闭当前窗口 
                        break;
                        #endregion
                    case "Funckey":
                        // MessageBox.Show("Func");
                        break;
                    case "Ctrlkey":
                        break;
                    case "Altkey":
                        break;
                    case "Delkey":
                        #region case "Delkey":
                        if (istbwulengjingchangshuFocused) tbstringfun(TBwulengjingchangshu, 3, "*");
                        if (istbTByoulengjingchangshuFocused) tbstringfun(TByoulengjingchangshu, 3, "*");                        
                        break;
                        #endregion
                    case "Tabkey":
                        #region
 /*                       switch (txtfocus)
                        {
                            case 0:
                                txtfocus = txtfocus + 1;
                                TByoulengjingchangshu.Focus();

                                break;
                            case 1:
                                txtfocus = txtfocus + 1;
                                istbTByoulengjingchangshuFocused.Focus();

                                break;
                            default:
                                txtfocus = 0;
                                tbItemName.Focus();
                                break;
                        }*/
                        break;
                        #endregion
                    case "BSkey":
                        #region case "BSkey":
                        if (istbwulengjingchangshuFocused) tbstringfun(TBwulengjingchangshu, 2, "*");
                        if (istbTByoulengjingchangshuFocused) tbstringfun(TByoulengjingchangshu, 2, "*");
                      
                        break;
                        #endregion
                    case "Shiftkey":
                        #region case "Shiftkey":
                        if (isnumber)
                        {

                            isnumber = false;

                            //                      MessageBox.Show("字母键盘");
                            Bt0key.Content = "#$%";
                            Btptkey.Content = "!&@";
                            Bt_key.Content = "+*/";
                            Bt1key.Content = "STU";
                            Bt2key.Content = "VWX";
                            Bt3key.Content = "YZ";
                            Bt4key.Content = "JKL";
                            Bt5key.Content = "MNO";
                            Bt6key.Content = "PQR";
                            Bt7key.Content = "ABC";
                            Bt8key.Content = "DEF";
                            Bt9key.Content = "GHI";
                        }
                        else
                        {
                            isnumber = true;
                            timer.IsEnabled = false;
                            //                           MessageBox.Show("数字键盘");
                            Bt0key.Content = "0";
                            Btptkey.Content = ".";
                            Bt_key.Content = "-";
                            Bt1key.Content = "1";
                            Bt2key.Content = "2";
                            Bt3key.Content = "3";
                            Bt4key.Content = "4";
                            Bt5key.Content = "5";
                            Bt6key.Content = "6";
                            Bt7key.Content = "7";
                            Bt8key.Content = "8";
                            Bt9key.Content = "9";
                        }
                        if (istbwulengjingchangshuFocused) TBwulengjingchangshu.Focus();
                        if (istbTByoulengjingchangshuFocused) TByoulengjingchangshu.Focus();
                        break;
                        #endregion
                    case "SPkey":
                        #region
                        if (istbwulengjingchangshuFocused) tbstringfun(TBwulengjingchangshu, 0, bt.Content.ToString());
                        if (istbTByoulengjingchangshuFocused) tbstringfun(TByoulengjingchangshu, 0, bt.Content.ToString());
 
                        break;
                        #endregion
                    case "ESCkey":
                        #region
                        ESC_Click(sender, e);
                        break;
                        #endregion
                    case "ENTkey":
                        #region case "ENTkey":

                        break;
                        #endregion

                    case "BtDnkey":
                        #region
                        switch (txtfocus)
                        {
                            case 0:
                                txtfocus = txtfocus + 1;
                                TByoulengjingchangshu.Focus();
                                break;
;
                            default:
                                txtfocus = 0;
                                TBwulengjingchangshu.Focus();
                                break;
                        }
                        break;
                        #endregion
                    case "BtUpkey":
                        #region case "BtUpkey"
                        switch (txtfocus)
                        {
                            case 1:
                                txtfocus = txtfocus - 1;
                                TBwulengjingchangshu.Focus();
                                break;
                            default:
                                txtfocus = 1;
                                TByoulengjingchangshu.Focus();
                                break;
                        }
                        break;
                        #endregion
                    case "BtLtkey":
                        #region
                        if (istbwulengjingchangshuFocused)
                        {
                            selectPos = this.TBwulengjingchangshu.SelectionStart;
                            TBwulengjingchangshu.Focus();
                            if (selectPos >= 1)
                            {

                                TBwulengjingchangshu.Select(selectPos - 1, 0);
                            }
                        }
                        if (istbTByoulengjingchangshuFocused)
                        {
                            selectPos = this.TByoulengjingchangshu.SelectionStart;
                            TByoulengjingchangshu.Focus();
                            if (selectPos >= 1)
                            {
                                TByoulengjingchangshu.Select(selectPos - 1, 0);
                            }
                        }
                        break;
                        #endregion
                    case "BtRtkey":
                        #region
                        istimeout = true;
                        lastkey = null;
                        if (istbTByoulengjingchangshuFocused) 
                        {
                            selectPos = this.TByoulengjingchangshu.SelectionStart;
                            TByoulengjingchangshu.Focus();
                            if (selectPos < this.TByoulengjingchangshu.Text.Length)
                            {
                                TByoulengjingchangshu.Select(selectPos + 1, 0);
                            }
                        }
                        if (istbwulengjingchangshuFocused)
                        {
                            selectPos = this.TBwulengjingchangshu.SelectionStart;
                            TBwulengjingchangshu.Focus();
                            if (selectPos < TBwulengjingchangshu.Text.Length)
                            {
                                TBwulengjingchangshu.Select(selectPos + 1, 0);
                            }
                        }
                        break;
                        #endregion
                    default:
                        #region default:
                        if (isnumber)
                        {
                            if (istbwulengjingchangshuFocused) tbstringfun(TBwulengjingchangshu, 0, bt.Content.ToString());
                            if (istbTByoulengjingchangshuFocused) tbstringfun(TByoulengjingchangshu, 0, bt.Content.ToString());                          
                        }
                        else
                        {

                            string press = bt.Name.ToString();
                            timer.Stop();
                            timer.Start();
                            if (press != lastkey)
                            {
                                lastkey = press;
                                istimeout = true;
                                keyNumber = 1;
                            }
                            else
                            {
                                keyNumber++;
                            }
                            if (istbwulengjingchangshuFocused)
                            {
                                switch (keyNumber % 3)
                                {
                                    case 0:
                                        if (istimeout)
                                        {
                                            tbstringfun(TBwulengjingchangshu, 0, bt.Content.ToString().Substring(2, 1));
                                        }
                                        else
                                        {
                                            tbstringfun(TBwulengjingchangshu, 1, bt.Content.ToString().Substring(2, 1));
                                        }
                                        break;
                                    case 1:
                                        if (istimeout)
                                        {
                                            tbstringfun(TBwulengjingchangshu, 0, bt.Content.ToString().Substring(0, 1));
                                        }
                                        else
                                        {
                                            tbstringfun(TBwulengjingchangshu, 1, bt.Content.ToString().Substring(0, 1));
                                        }
                                        break;
                                    case 2:
                                        if (istimeout)
                                        {
                                            tbstringfun(TBwulengjingchangshu, 0, bt.Content.ToString().Substring(1, 1));
                                        }
                                        else
                                        {
                                            tbstringfun(TBwulengjingchangshu, 1, bt.Content.ToString().Substring(1, 1));
                                        }
                                        break;
                                }
                            }
#region
                            if (istbTByoulengjingchangshuFocused)
                            {
                                switch (keyNumber % 3)
                                {
                                    case 0:
                                        if (istimeout)
                                        {
                                            tbstringfun(TByoulengjingchangshu, 0, bt.Content.ToString().Substring(2, 1));
                                        }
                                        else
                                        {
                                            tbstringfun(TByoulengjingchangshu, 1, bt.Content.ToString().Substring(2, 1));
                                        }
                                        break;
                                    case 1:
                                        if (istimeout)
                                        {
                                            tbstringfun(TByoulengjingchangshu, 0, bt.Content.ToString().Substring(0, 1));
                                        }
                                        else
                                        {
                                            tbstringfun(TByoulengjingchangshu, 1, bt.Content.ToString().Substring(0, 1));
                                        }
                                        break;
                                    case 2:
                                        if (istimeout)
                                        {
                                            tbstringfun(TByoulengjingchangshu, 0, bt.Content.ToString().Substring(1, 1));
                                        }
                                        else
                                        {
                                            tbstringfun(TByoulengjingchangshu, 1, bt.Content.ToString().Substring(1, 1));
                                        }
                                        break;
                                 }
#endregion
                               }                           
                            }
                            istimeout = false;
                            break;
                        }
                        #endregion
                }
        }