private void cbProgram_SelectionChanged(object sender, SelectionChangedEventArgs e) { bAddCommand.IsEnabled = false; if (cbProgram.SelectedItem != null) { if (cbProgram.SelectedItem.ToString() == "Системные команды") { lTypeCommand.Content = "Тип команды: "; cbTypeCommand.Items.Clear(); cbTypeCommand.Items.Add("Кнопки мыши"); cbTypeCommand.Items.Add("Перемещение мыши"); cbTypeCommand.Items.Add("Ожидание"); cbTypeCommand.Items.Add("Повтор"); } else { lTypeCommand.Content = "Компонент: "; cbTypeCommand.Items.Clear(); CppLib.ProcessInfo buff = Proc.Find(x => x.Name == cbProgram.SelectedItem.ToString()); List <CppLib.ChildEll> ell = CppLib.GetNeedChildEll(buff.Handle, options.Ellements.ToArray()); for (int i = 0; i < ell.Count; i++) { if (ell[i].Name == "") { cbTypeCommand.Items.Add(i + "." + ell[i].ClassEll); } else { cbTypeCommand.Items.Add(i + "." + ell[i].ClassEll + " \"" + ell[i].Name.Replace("&", "") + "\""); } } cbTypeCommand.Items.Add(ell.Count + ".Контекстное меню"); } } }
private void bExeScript_Click(object sender, RoutedEventArgs e) { List <int[]> Repeat = new List <int[]>(); int counter = options.CounterStart; int counter2 = 0; UpdatecbProgram(); Stop = false; for (int i = 0; i < lvScript.Items.Count; i++) { lvScript.SelectedIndex = i; UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(lvScript.SetValue); Dispatcher.Invoke(updatePbDelegate, DispatcherPriority.Background, new object[] { System.Windows.Controls.ListView.SelectedIndexProperty, i }); UpdateProgressBarDelegate updatePbDelegate2 = new UpdateProgressBarDelegate(sblInfo.SetValue); if (Repeat.Count > counter2) { Dispatcher.Invoke(updatePbDelegate2, DispatcherPriority.Background, new object[] { System.Windows.Controls.Label.ContentProperty, "Осталось ещё " + Repeat[counter2][0] + " повторов" }); } ScriptItem item = new ScriptItem { Program = ((ScriptItem)lvScript.Items[i]).Program, TypeCommand = ((ScriptItem)lvScript.Items[i]).TypeCommand, Command = ((ScriptItem)lvScript.Items[i]).Command }; if (Stop == true) { sblInfo.Content = ""; Stop = false; lvScript.SelectedIndex = lvScript.Items.Count - 1; return; } while (true) { if (cbCounter.IsChecked == true && item.Command.Contains(options.CounterText) == true) { string buff2 = item.Command.Remove(item.Command.IndexOf(options.CounterText)); buff2 = buff2 + counter + item.Command.Remove(0, item.Command.IndexOf(options.CounterText) + options.CounterText.Length); item.Command = buff2; } else { break; } } switch (item.TypeCommand) { case "Кнопки мыши": switch (item.Command) { case "Правая кнопка мыши": CppLib.MouseClickOnDesktop(MyMouseEvent.Mouse_Right_Click); break; case "Левая кнопка мыши": CppLib.MouseClickOnDesktop(MyMouseEvent.Mouse_Left_Click); break; case "Правая кнопка мыши вниз": CppLib.MouseClickOnDesktop(MyMouseEvent.Mouse_Right_Down); break; case "Правая кнопка мыши вверх": CppLib.MouseClickOnDesktop(MyMouseEvent.Mouse_Right_Up); break; case "Левая кнопка мыши вниз": CppLib.MouseClickOnDesktop(MyMouseEvent.Mouse_Left_Down); break; case "Левая кнопка мыши вверх": CppLib.MouseClickOnDesktop(MyMouseEvent.Mouse_Left_Up); break; } break; case "Перемещение мыши": System.Windows.Forms.Cursor.Position = new System.Drawing.Point(Convert.ToInt32(item.Command.Split(' ')[1]), Convert.ToInt32(item.Command.Split(' ')[3])); break; case "Ожидание": long tiks = DateTime.Now.Ticks + (long)(Convert.ToDouble(item.Command.Split(' ')[0].Replace('.', ',')) * 10000000); while (true) { if (DateTime.Now.Ticks >= tiks) { break; } Dispatcher.Invoke(updatePbDelegate, DispatcherPriority.Background, new object[] { System.Windows.Controls.ListView.SelectedIndexProperty, i }); if (Stop == true) { sblInfo.Content = ""; Stop = false; lvScript.SelectedIndex = lvScript.Items.Count - 1; return; } } break; case "Повтор": counter = counter + options.CounterStep; counter2 = 0; for (int j = 0; j < Repeat.Count + 1; j++) { if (j == Repeat.Count) { for (int k = 0; k < Repeat.Count; k++) { Repeat[k][0] = Repeat[k][1]; } Repeat.Add(new int[3] { Convert.ToInt32(item.Command), Convert.ToInt32(item.Command), i }); counter2 = j; break; } if (Repeat[j][2] == i) { counter2 = j; break; } } if (Repeat[counter2][0] != 0) { Repeat[counter2][0]--; i = -1; continue; } break; default: UpdatecbProgram(); CppLib.ProcessInfo Process = Proc.Find(x => x.Name == item.Program); List <CppLib.ChildEll> ellements = CppLib.GetNeedChildEll(Process.Handle, options.Ellements.ToArray()); string spliteType = item.TypeCommand.Split(' ')[0]; string[] splitCommand = item.Command.Split(' '); string number = spliteType.Remove(spliteType.IndexOf('.'), spliteType.Length - 1); string name = spliteType.Remove(0, spliteType.IndexOf('.') + 1); if (name == "Контекстное") { Bitmap screenAfterClick, screenBeforClick; Graphics graphScreenAfterClick, graphScreenBeforClick; System.Drawing.Color[] colorsScreenAfterClick, colorsScreenBeforClick; screenAfterClick = new Bitmap(Process.Border.right - Process.Border.left, Process.Border.bottom - Process.Border.top); graphScreenAfterClick = Graphics.FromImage(screenAfterClick); screenBeforClick = new Bitmap(Process.Border.right - Process.Border.left, Process.Border.bottom - Process.Border.top); graphScreenBeforClick = Graphics.FromImage(screenBeforClick); graphScreenBeforClick.CopyFromScreen(new System.Drawing.Point(Process.Border.left, Process.Border.top), System.Drawing.Point.Empty, new System.Drawing.Size(Process.Border.right - Process.Border.left, Process.Border.bottom - Process.Border.top)); System.Windows.Forms.Cursor.Position = new System.Drawing.Point(Convert.ToInt32(splitCommand[1]), Convert.ToInt32(splitCommand[3])); CppLib.MouseClickOnDesktop(MyMouseEvent.Mouse_Right_Click); long tiks2 = DateTime.Now.Ticks + (long)(Convert.ToDouble(0.5 * 10000000)); colorsScreenBeforClick = GetColorArr(screenBeforClick); while (true) { if (DateTime.Now.Ticks >= tiks2) { break; } if (Stop == true) { sblInfo.Content = ""; Stop = false; lvScript.SelectedIndex = lvScript.Items.Count - 1; return; } } graphScreenAfterClick.CopyFromScreen(new System.Drawing.Point(Process.Border.left, Process.Border.top), System.Drawing.Point.Empty, new System.Drawing.Size(Process.Border.right - Process.Border.left, Process.Border.bottom - Process.Border.top)); colorsScreenAfterClick = GetColorArr(screenAfterClick); for (int y = 0; y < screenBeforClick.Height; y++) { for (int x = 0; x < screenBeforClick.Width; x++) { screenBeforClick.SetPixel(x, y, colorsScreenBeforClick[x + y * screenBeforClick.Width]); } } image1.Source = BitmapToImageSource(screenBeforClick); for (int y = 0; y < screenAfterClick.Height; y++) { for (int x = 0; x < screenAfterClick.Width; x++) { screenAfterClick.SetPixel(x, y, colorsScreenAfterClick[x + y * screenBeforClick.Width]); } } image.Source = BitmapToImageSource(screenAfterClick); } else { for (int j = 0; j < ellements.Count; j++) { if (name == "Edit" && j == Convert.ToInt32(number)) { for (int k = 0; k < cbTypeCommand.Items.Count; k++) { if (number + ".Edit" == cbTypeCommand.Items[k].ToString().Split(' ')[0]) { cbTypeCommand.Items[k] = number + ".Edit \"" + item.Command + "\""; break; } } CppLib.SetTitleText(ellements[j].Handle, item.Command); break; } if (name == "Button" && j == Convert.ToInt32(number)) { CppLib.ClickButton(ellements[j].Handle); break; } } } break; } } sblInfo.Content = ""; }