private void GBGClickAddModifyRecord_Load(Object sender, EventArgs e) { cbRecordType.DisplayMember = "Key"; cbRecordType.ValueMember = "Value"; foreach (ClickRecordType recordType in Enum.GetValues(typeof(ClickRecordType))) { cbRecordType.Items.Add(new KeyValuePair <String, Type>(recordType.ToString(), typeof(ClickRecordType))); } // Tack on "Duration" at the end as well cbRecordType.Items.Add( new KeyValuePair <String, Type>( DurationRecordType.Duration.ToString(), typeof(DurationRecordType))); cbRecordType.SelectedIndexChanged += new EventHandler((sendr, evtargs) => { KeyValuePair <String, Type> selection = (KeyValuePair <String, Type>)cbRecordType.SelectedItem; if (selection.Key == DurationRecordType.Duration.ToString()) { showMS(); } else { showXY(); } btnOk.Enabled = true; }); if (newRecord != null) { Text = "Modify a record"; if (newRecord.Type == RecordType.DurationRecord) { cbRecordType.SelectedIndex = cbRecordType.Items.Count - 1; GUIUtilities.SetNumericUpDownValue(numDuration, ((DurationRecord)newRecord).Duration); } else { ClickRecord newRecordActual = (ClickRecord)newRecord; cbRecordType.SelectedIndex = (Int32)newRecordActual.SubType; Point point = newRecordActual.TargetPoint; numX.Value = point.X; numY.Value = point.Y; } } else { Text = "Create a record"; } }
private void RunBot_Work(Object sender, DoWorkEventArgs e) { if (bgw.CancellationPending) { e.Cancel = true; } else if (itr < profileController.ActiveProfile.NodeList.Count) { GenericNode node = profileController.ActiveProfile.NodeList[itr]; activeNode = node; InternalNodeSettings nodeSettings = node.Settings.internalNodeSettings; InternalTimeSettings timeSettings = node.Settings.internalTimeSettings; BindingList <RecordBase> records = node.Settings.Records; Int32 runs = nodeSettings.Runs; if (nodeSettings.Enabled != CheckState.Unchecked) { while (!bgw.CancellationPending && runs-- > 0) { foreach (RecordBase record in records) { if (bgw.CancellationPending) { e.Cancel = true; return; } activeRecord = record; bgw.ReportProgress(itr * 4); if (runs > 0) { activeRepeats = runs; bgw.ReportProgress(itr * 4 + 1); } if (record.Type == RecordType.DurationRecord) { // This code allows users to stop the bot during long sleeps Int32 duration = ((DurationRecord)record).Duration, iterations = duration / DURATION_ITERATION_INTERVAL, remainder = duration % DURATION_ITERATION_INTERVAL; if (duration > DURATION_ITERATION_INTERVAL * DURATION_ITERATION_MARGIN) { for (Int32 i = 0; i < iterations; ++i) { System.Threading.Thread.Sleep(DURATION_ITERATION_INTERVAL); if (bgw.CancellationPending) { e.Cancel = true; return; } } System.Threading.Thread.Sleep(remainder); } else { System.Threading.Thread.Sleep(duration); } } else if (record.Type == RecordType.ClickRecord) { bgw.ReportProgress(itr * 4 + 2); Random rand = new Random(); Int32 mouseMoveDuration = rand.Next(1000); switch (nodeSettings.MouseSpeed) { case MouseSpeed.Slow: mouseMoveDuration = rand.Next(800, 1500); break; case MouseSpeed.Medium: mouseMoveDuration = rand.Next(500, 900); break; case MouseSpeed.Fast: mouseMoveDuration = rand.Next(100, 600); break; case MouseSpeed.Random: mouseMoveDuration = rand.Next(rand.Next(100, 600), rand.Next(700, 1500)); break; } ClickRecord clickRecord = (ClickRecord)record; // Take into account the global and local offsets (they do indeed stack) Point targetPoint = clickRecord.TargetPoint; targetPoint.X += (applicationSettings.GlobalOffsetX + nodeSettings.OffsetX); targetPoint.Y += (applicationSettings.GlobalOffsetY + nodeSettings.OffsetY); MouseController.SmoothClickMouseTo(targetPoint, mouseMoveDuration, clickRecord.SubType); } activeString = "intranode"; bgw.ReportProgress(itr * 4 + 3); Int32 sleeptimeIntranode = 0; // seconds if (applicationSettings.IntranodeForcedPauseEnabled != CheckState.Unchecked) { sleeptimeIntranode = timeSettings.ForcedPause; } if (applicationSettings.IntranodeEntropyEnabled != CheckState.Unchecked) { Random rand = new Random(); switch (timeSettings.Entropy) { case EntropyLevel.Low: sleeptimeIntranode += rand.Next(100); break; case EntropyLevel.Medium: sleeptimeIntranode += rand.Next(500); break; case EntropyLevel.High: sleeptimeIntranode += rand.Next(1000); break; } } System.Threading.Thread.Sleep(sleeptimeIntranode); } } if (bgw.CancellationPending) { e.Cancel = true; return; } activeString = "internode"; bgw.ReportProgress(itr * 4 + 3); Int32 sleeptimeInternode = 10000; // milliseconds Random randInternode = new Random(); switch (applicationSettings.InternodeEntropy) { case EntropyLevel.Low: sleeptimeInternode += randInternode.Next(10000); break; case EntropyLevel.Medium: sleeptimeInternode += randInternode.Next(30000); break; case EntropyLevel.High: sleeptimeInternode += randInternode.Next(90000); break; } System.Threading.Thread.Sleep(sleeptimeInternode); } else { bgw.ReportProgress(itr * 4 + 4); } } if (bgw.CancellationPending) { e.Cancel = true; } }