static public void SetCursorPositionOnTarget(Vector3 target) { var mousePositionClient = gameController.Game.IngameState.Camera.WorldToScreen(target); var gameWindowRect = gameController.Window.GetWindowRectangle(); Vector2 mousePositionScreen = gameWindowRect.TopLeft + mousePositionClient; if (mousePositionScreen.PointInRectangle(gameWindowRect) == false) { float clampedX = MyExtensions.Clamp <float>(mousePositionScreen.X, gameWindowRect.TopLeft.X + 10, gameWindowRect.TopRight.X - 10); float clampedY = MyExtensions.Clamp <float>(mousePositionScreen.Y, gameWindowRect.TopLeft.Y + 10, gameWindowRect.BottomLeft.Y - 10); mousePositionScreen = new Vector2(clampedX, clampedY); Console.WriteLine("clamped mouse position in SetCursorPositionOnTarget"); Input.SetCursorPos(mousePositionScreen); } else { Input.SetCursorPos(mousePositionScreen); } }
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); } }