public static async Task ClickOnPoint(ExportingInfo info, String nameInDictionary) { Hearthstone_Deck_Tracker.API.Core.MainWindow.Topmost = false; var clickPos = new Point((int)Helper.GetScaledXPos(ExportPoints[nameInDictionary].X, info.HsRect.Width, info.Ratio), (int)(ExportPoints[nameInDictionary].Y * info.HsRect.Height)); await MouseActions.ClickOnPoint(info.HsHandle, clickPos); }
public static async void ClickOnPoint(double pointX, double pointY) { Hearthstone_Deck_Tracker.API.Core.MainWindow.Topmost = false; var info = new ExportingInfo(); var clickPos = new Point((int)Helper.GetScaledXPos(pointX, info.HsRect.Width, info.Ratio), (int)(pointY * info.HsRect.Height)); await MouseActions.ClickOnPoint(info.HsHandle, clickPos); }
public async Task ClickOnPoint(Point clientPoint) { if (!User32.IsHearthstoneInForeground() || (_onUnexpectedMousePos != null && _previousCursorPos != Point.Empty && (Math.Abs(_previousCursorPos.X - Cursor.Position.X) > 10 || Math.Abs(_previousCursorPos.Y - Cursor.Position.Y) > 10))) { if (!(_onUnexpectedMousePos == null || await _onUnexpectedMousePos())) { throw new ExportingInterruptedException("Export interrupted, not continuing"); } if ((_info = await ExportingHelper.EnsureHearthstoneInForeground(_info)) == null) { throw new ExportingInterruptedException("Export interrupted - could not re-focus hearthstone"); } await Task.Delay(500); } User32.ClientToScreen(_info.HsHandle, ref clientPoint); Cursor.Position = _previousCursorPos = new Point(clientPoint.X, clientPoint.Y); Log.Debug("Clicking " + Cursor.Position); //mouse down if (SystemInformation.MouseButtonsSwapped) { User32.mouse_event((uint)User32.MouseEventFlags.RightDown, 0, 0, 0, UIntPtr.Zero); } else { User32.mouse_event((uint)User32.MouseEventFlags.LeftDown, 0, 0, 0, UIntPtr.Zero); } await Task.Delay(Config.Instance.DeckExportDelay); //mouse up if (SystemInformation.MouseButtonsSwapped) { User32.mouse_event((uint)User32.MouseEventFlags.RightUp, 0, 0, 0, UIntPtr.Zero); } else { User32.mouse_event((uint)User32.MouseEventFlags.LeftUp, 0, 0, 0, UIntPtr.Zero); } await Task.Delay(Config.Instance.DeckExportDelay); }
public MouseActions(ExportingInfo info, Func <Task <bool> > onUnexpectedMousePos) { _info = info; _onUnexpectedMousePos = onUnexpectedMousePos; }
public static async void ExportDeck(Deck deck, bool autoFinish = false) { var export = true; var info = new ExportingInfo(); int pause = 1000; if (Config.Instance.ShowExportingDialog) { var message = $"1) create a new {deck.Class} deck{(Config.Instance.AutoClearDeck ? " (or open an existing one to be cleared automatically)" : "")}.\n\n2) leave the deck creation screen open.\n\n3) do not move your mouse or type after clicking \"export\"."; if (deck.GetSelectedDeckVersion().Cards.Any(c => c.Name == "Stalagg" || c.Name == "Feugen")) { message += "\n\nIMPORTANT: If you own golden versions of Feugen or Stalagg please make sure to configure\nOptions > Other > Exporting"; } var settings = new Hearthstone_Deck_Tracker.Windows.MessageDialogs.Settings { AffirmativeButtonText = "Export" }; var result = await Hearthstone_Deck_Tracker.API.Core.MainWindow.ShowMessageAsync("Export " + deck.Name + " to Hearthstone", message, MessageDialogStyle.AffirmativeAndNegative, settings); export = result == MessageDialogResult.Affirmative; } if (export) { Hearthstone_Deck_Tracker.API.Core.MainWindow.Topmost = false; var inForeground = await ExportingHelper.EnsureHearthstoneInForeground(info.HsHandle); if (!inForeground) { return; } var controller = await Hearthstone_Deck_Tracker.API.Core.MainWindow.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type."); await Task.Delay(pause); await ClickOnPoint(info, deck.Class); await Task.Delay(pause); await ClickOnPoint(info, "ClassChoose"); await Task.Delay(pause); await ClickOnPoint(info, "RecipeCustom"); await Task.Delay(pause); await ClickOnPoint(info, "RecipeChoose"); await Task.Delay(pause); await DeckExporter.Export(deck); await controller.CloseAsync(); if (deck.MissingCards.Any()) { Hearthstone_Deck_Tracker.Windows.MessageDialogs.ShowMissingCardsMessage(Hearthstone_Deck_Tracker.API.Core.MainWindow, deck); } } if (autoFinish) { await ClickOnPoint(info, "Done"); await Task.Delay(pause); await ClickOnPoint(info, "QuestionYes"); } }