public static bool SetCursorPosAndLeftOrRightClick(LabelOnGround labelOnGround, int extraDelay, MyMouseClicks clickType = MyMouseClicks.LeftClick, bool useCache = true, bool randomClick = false) { try { var label = labelOnGround?.Label; if (label == null) { return(false); } RectangleF clientRect; if (useCache) { clientRect = label.GetClientRectCache; } else { clientRect = label.GetClientRect(); } return(SetCursorPosAndLeftOrRightClick(clientRect, extraDelay, clickType: clickType, randomClick: randomClick)); } catch { return(false); } }
public static bool SetCursorPosAndLeftOrRightClick(RectangleF rect, int extraDelay, MyMouseClicks clickType = MyMouseClicks.LeftClick, bool randomClick = false) { try { var gameWindowRect = GameController.Window.GetWindowRectangle(); int posX = 0; int posY = 0; if (randomClick) { // Constrain to center +- x percent of width and height int xRandomStart = (int)(rect.Center.X - 0.1f * rect.Width); int xRandomStop = (int)(rect.Center.X + 0.1f * rect.Width); int yRandomStart = (int)(rect.Center.Y - 0.1f * rect.Height); int yRandomStop = (int)(rect.Center.Y + 0.1f * rect.Height); posX = (int)gameWindowRect.TopLeft.X + ExileCore.Shared.Helpers.MathHepler.Randomizer.Next(xRandomStart, xRandomStop); posY = (int)gameWindowRect.TopLeft.Y + ExileCore.Shared.Helpers.MathHepler.Randomizer.Next(yRandomStart, yRandomStop); } else { posX = (int)gameWindowRect.TopLeft.X + (int)rect.Center.X; posY = (int)gameWindowRect.TopLeft.Y + (int)rect.Center.Y; } var inventory = GameController.Game.IngameState.IngameUi.InventoryPanel[InventoryIndex.PlayerInventory]; var inventoryRect = inventory.GetClientRectCache; RectangleF blacklistedRectangleIfPlayerInventoryVisible = new RectangleF(inventoryRect.TopRight.X, 0, inventoryRect.Width, inventoryRect.TopLeft.Y); var inputRect = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height); if (inventory.IsVisible == true && blacklistedRectangleIfPlayerInventoryVisible.Contains(inputRect) == true) { WillBot.LogMessageCombo("Player inventory is visible and you tried to click inside the active items rectangle."); return(false); } // Clamp away x percent of screen height and width float clampFactor = 0.1f; posX = (int)MyExtensions.Clamp <float>(posX, gameWindowRect.TopLeft.X + 5, gameWindowRect.TopRight.X - 5); posY = (int)MyExtensions.Clamp <float>(posY, gameWindowRect.TopLeft.Y + 0.05f * gameWindowRect.Height, gameWindowRect.BottomLeft.Y - clampFactor * gameWindowRect.Height); SetCursorPos(posX, posY); Thread.Sleep(MovementDelay + extraDelay); switch (clickType) { case MyMouseClicks.LeftClick: LeftClick(ClickDelay); break; case MyMouseClicks.RightClick: RightClick(ClickDelay); break; case MyMouseClicks.NoClick: break; case MyMouseClicks.MiddleClick: break; } return(true); } catch { return(false); } }
public static bool SetCursorPosAndLeftOrRightClick(Vector2 screenPos, int extraDelay, MyMouseClicks clickType = MyMouseClicks.LeftClick) { try { RectangleF clientRect = new RectangleF(screenPos.X, screenPos.Y, 1, 1); return(SetCursorPosAndLeftOrRightClick(clientRect, extraDelay, clickType: clickType, randomClick: false)); } catch { return(false); } }