//松开鼠标键触发的事件
        private void mh_MouseUpEvent(object sender, MouseEventArgs e)
        {
            if (!IsStart)
            {
                return;
            }
            t2 = timeTickRecord;
            p2 = e.Location;
            string text = "";

            if (t2 - t1 <= 20 && p1 == p2)
            {
                text += timeToString() + "\n完成了点击动作";
            }
            else
            if (p1 == p2)
            {
                text += timeToString() + "\n完成了长按动作";
            }
            else
            {
                text += timeToString() + "\n完成了拖动动作";
            }

            if (e.Button == MouseButtons.Left)
            {
                text += "(左键)";
            }
            if (e.Button == MouseButtons.Right)
            {
                text += "(右键)";
                //SendKeys.Send("{}");
            }
            if (p1 != p2)
            {
                text += "\n\t" + "拖动鼠标从:(x:" + p1.X + ",y:" + p1.Y + ")\n\t到(x:" + p2.X + ",y:" + p2.Y + ")位置\n";
            }
            else if (t2 - t1 > 20)
            {
                text += "(x:" + p1.X + ",y:" + p1.Y + ")\n\t" + "长按了:" + timeToString(t2 - t1) + "\n";
            }
            else
            {
                text += "(x:" + p1.X + ",y:" + p1.Y + ")\n";
            }
            text += "============\n";
            richTextBox1.Text = text + richTextBox1.Text;
            RightTag          = false;
            LeftTag           = false;
            p1 = new Point(0, 0);
            p2 = new Point(0, 0);
            dateArr.Add(Date1.create(timeTickRecord,
                                     Date1.IsMouseOrKeyboard.Mouse,
                                     Date1.IsUpOrDown.Up,
                                     e));
        }
 private void timer1_Tick(object sender, EventArgs e)
 {
     timeTickRecord++;
     timeTickConst = 1000 / this.timer1.Interval;
     label1.Text   = timeToString();
     if (mh != null)
     {
         var e2 = new MouseEventArgs(MouseButtons.None, 0, p3.X, p3.Y, 0);
         dateArr.Add(Date1.create(timeTickRecord,
                                  Date1.IsMouseOrKeyboard.Mouse,
                                  Date1.IsUpOrDown.Move,
                                  e2));
     }
 }
        public static Date1 create(long timeTickRecord, IsMouseOrKeyboard isMouseOrKeyboard, IsUpOrDown isUpOrDown, EventArgs eventArgs)
        {
            Date1 date1 = null;

            if (isMouseOrKeyboard == IsMouseOrKeyboard.Mouse)
            {
                date1 = new Date1(timeTickRecord, isMouseOrKeyboard, isUpOrDown, (MouseEventArgs)eventArgs);
            }
            if (isMouseOrKeyboard == IsMouseOrKeyboard.Keyboard)
            {
                date1 = new Date1(timeTickRecord, isMouseOrKeyboard, isUpOrDown, (KeyEventArgs)eventArgs);
            }
            return(date1);
        }
 //按下鼠标键触发的事件
 private void mh_MouseDownEvent(object sender, MouseEventArgs e)
 {
     if (!IsStart)
     {
         return;
     }
     if (e.Button == MouseButtons.Left)
     {
         LeftTag = true;
     }
     if (e.Button == MouseButtons.Right)
     {
         RightTag = true;
     }
     p1 = e.Location;
     t1 = timeTickRecord;
     dateArr.Add(Date1.create(timeTickRecord,
                              Date1.IsMouseOrKeyboard.Mouse,
                              Date1.IsUpOrDown.Down,
                              e));
 }
        public static Date1 create(
            long timeTickRecord,
            IsMouseOrKeyboard isMouseOrKeyboard,
            IsUpOrDown isUpOrDown,
            KeyEventArgs keyEventArgs,
            MouseButtons mouseButtons,
            int X,
            int Y,
            int MouseDelta)
        {
            Date1 date1 = null;

            if (isMouseOrKeyboard == IsMouseOrKeyboard.Mouse)
            {
                date1 = new Date1(timeTickRecord, isMouseOrKeyboard, isUpOrDown, new MouseEventArgs(mouseButtons, 0, X, Y, MouseDelta));
            }
            if (isMouseOrKeyboard == IsMouseOrKeyboard.Keyboard)
            {
                date1 = new Date1(timeTickRecord, isMouseOrKeyboard, isUpOrDown, keyEventArgs);
            }
            return(date1);
        }
        private void Hook_MouseWheelExt(object sender, MouseEventExtArgs e)
        {
            if (!IsStart)
            {
                return;
            }
            string text = "";

            if (e.Delta > 0)        //鼠标滚轮向前
            {
                text += "滚轮向上移动";
            }
            else
            {
                text += "滚轮向下移动";
            }
            text += "\n============\n";
            richTextBox1.Text = text + richTextBox1.Text;

            dateArr.Add(Date1.create(timeTickRecord,
                                     Date1.IsMouseOrKeyboard.Mouse,
                                     Date1.IsUpOrDown.Wheel,
                                     e));
        }
        void DownData(int mainkey)
        {
            string sql;

            //获取动作长度
            sql = "SELECT mainKey FROM data" + mainkey + " ORDER BY mainKey DESC LIMIT 1;";
            MySqlDataReader mySql = SQLManage.GetReader(sql);

            mySql.Read();
            int size = (int)mySql[0];

            SQLManage.closeConn();

            //弹出加载窗口
            Form9 form9 = new Form9("正在下载动作......");

            form9.progressBar1.Maximum = size;
            form9.progressBar1.Step    = 1;
            form9.Show();

            //创建临时动作保存
            List <Date1> date1 = new List <Date1>();

            sql   = "SELECT * FROM data" + mainkey + " ORDER BY mainKey;";
            mySql = SQLManage.GetReader(sql);
            while (mySql.Read())
            {
                //将数据库的动作读取出来

                long x1 = (long)mySql[1];
                Date1.IsMouseOrKeyboard x2 = (Date1.IsMouseOrKeyboard)mySql[2];
                Date1.IsUpOrDown        x3 = (Date1.IsUpOrDown)mySql[3];
                if (x2 == Date1.IsMouseOrKeyboard.Keyboard)
                {
                    Keys x4 = (Keys)mySql[4];
                    date1.Add(Date1.create(
                                  x1,
                                  x2,
                                  x3,
                                  new KeyEventArgs(x4)
                                  ));
                }
                if (x2 == Date1.IsMouseOrKeyboard.Mouse)
                {
                    MouseButtons x5 = (MouseButtons)mySql[5];
                    int          x6 = (int)mySql[6];
                    int          x7 = (int)mySql[7];
                    int          x8 = (int)mySql[8];
                    date1.Add(Date1.create(
                                  x1,
                                  x2,
                                  x3,
                                  new MouseEventArgs(x5, 0, x6, x7, x8)
                                  ));
                }
                //进度条往前一格
                form9.progressBar1.PerformStep();
            }
            //读取完毕
            SQLManage.closeConn();

            //读取动作名称长度介绍等信息
            sql   = "SELECT * FROM amainform WHERE mainKey = " + mainkey + ";";
            mySql = SQLManage.GetReader(sql);
            mySql.Read();
            formName    = (string)mySql[1];
            formTime    = (string)mySql[2];
            formMessage = (string)mySql[3];
            SQLManage.closeConn();
            form9.Close();
            form9.Dispose();

            //同步主窗口和本窗口的数据
            dates                = date1;
            mainForm.dates       = date1;
            mainForm.formName    = formName;
            mainForm.formTime    = formTime;
            mainForm.formMessage = formMessage;

            MessageBox.Show(formName + "\n动作下载完成");
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (dateArr.Count > 0 && p < dateArr.Count)
            {
                while (p < dateArr.Count && dateArr.ElementAt(p).timeTickRecord <= timeTickRecord)
                {
                    //保存当前动作
                    Date1 d = dateArr.ElementAt(p);

                    if (d.isMouseOrKeyboard
                        == Date1.IsMouseOrKeyboard.Mouse)
                    {
                        //0x8000采用绝对坐标
                        //0x0001移动鼠标
                        int dwFlags = 0x8000 | 0x0001 | 0x0800;
                        int x       = 0;
                        int y       = 0;
                        //判断按键代码块
                        {
                            if (d.mouseEventArgs.Button == MouseButtons.Left)
                            {
                                if (d.isUpOrDown == Date1.IsUpOrDown.Down)
                                {
                                    dwFlags |= 0x0002;
                                }
                                if (d.isUpOrDown == Date1.IsUpOrDown.Up)
                                {
                                    dwFlags |= 0x0004;
                                }
                            }
                            if (d.mouseEventArgs.Button == MouseButtons.Right)
                            {
                                if (d.isUpOrDown == Date1.IsUpOrDown.Down)
                                {
                                    dwFlags |= 0x0008;
                                }
                                if (d.isUpOrDown == Date1.IsUpOrDown.Up)
                                {
                                    dwFlags |= 0x0010;
                                }
                            }
                        }
                        x = d.mouseEventArgs.X;
                        x = x * 65536 / Screen.PrimaryScreen.Bounds.Width;
                        y = d.mouseEventArgs.Y;
                        y = y * 65536 / Screen.PrimaryScreen.Bounds.Height;
                        mouse_event(dwFlags,
                                    x,
                                    y,
                                    d.mouseEventArgs.Delta, 0
                                    );
                    }

                    if (d.isMouseOrKeyboard
                        == Date1.IsMouseOrKeyboard.Keyboard)
                    {
                        int dwFlags = 0;
                        if (d.isUpOrDown == Date1.IsUpOrDown.Up)
                        {
                            dwFlags = 2;
                        }
                        keybd_event((byte)d.keyEventArgs.KeyValue
                                    , 0, dwFlags, 0);
                    }

                    //keybd_event
                    p++;
                }
            }
            timeTickRecord++;
            if (p >= dateArr.Count)
            {
                if (!isLoop)
                {
                    playCount--;
                    if (playCount > 0)
                    {
                        start();
                    }
                    else
                    {
                        stop();
                    }
                }
                else
                {
                    start();
                }
            }
        }
        void duqu()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = "动作信息文件(*.dodata)|*.dodata|所有文件|*.*";
            ofd.ValidateNames   = true;
            ofd.CheckPathExists = true;
            ofd.CheckFileExists = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string strFileName = ofd.FileName;
                //其他代码
                string[] lines = System.IO.File.ReadAllLines(strFileName);
                int      mod   = 1;

                //MessageBox.Show("读取成功");
                foreach (string line in lines)
                {
                    if (mod == 1 && !"《未加密动作信息》".Equals(line))
                    {
                        MessageBox.Show("警告!该文件非动作信息!");
                        return;
                    }
                    else if (mod == 1)
                    {
                        mod   = 2;
                        dates = new List <Date1>();
                        continue;
                    }
                    if (mod == 2)
                    {
                        formName = line;
                        mod++;
                        continue;
                    }
                    if (mod == 3)
                    {
                        formTime    = line;
                        formMessage = "";
                        mod++;
                        continue;
                    }
                    string temp = "<!===================================!>";

                    if (mod == 4 && !temp.Equals(line))
                    {
                        formMessage += line;
                        continue;
                    }
                    else if (mod == 4)
                    {
                        mod = 5;
                        continue;
                    }
                    if (mod == 5)
                    {
                        string[] str = line.Split(',');
                        long     x1  = long.Parse(str[0]);
                        Date1.IsMouseOrKeyboard x2 = (Date1.IsMouseOrKeyboard) int.Parse(str[1]);
                        Date1.IsUpOrDown        x3 = (Date1.IsUpOrDown) int.Parse(str[2]);
                        if (x2 == Date1.IsMouseOrKeyboard.Keyboard)
                        {
                            Keys x4 = (Keys)int.Parse(str[3]);
                            dates.Add(Date1.create(
                                          x1,
                                          x2,
                                          x3,
                                          new KeyEventArgs(x4)
                                          ));
                        }
                        if (x2 == Date1.IsMouseOrKeyboard.Mouse)
                        {
                            MouseButtons x5 = (MouseButtons)int.Parse(str[3]);
                            int          x6 = int.Parse(str[4]);
                            int          x7 = int.Parse(str[5]);
                            int          x8 = int.Parse(str[6]);
                            dates.Add(Date1.create(
                                          x1,
                                          x2,
                                          x3,
                                          new MouseEventArgs(x5, 0, x6, x7, x8)
                                          ));
                        }
                    }
                }
            }
        }