public void Interact() { var screen = System.Windows.Forms.Screen.PrimaryScreen.Bounds; var width = screen.Width; var height = screen.Height; bool found = false; int X = Cursor.Position.X; int Y = Cursor.Position.Y; IntPtr activeWindow = GetForegroundWindow(); for (int i = 0; i < width; i += 40) { for (int j = 0; j < height; j += 40) { Cursor.Position = new Point(i, j); short cursor = magic.ReadShort((uint)TbcOffsets.General.Cursor); if (cursor == 16 || cursor == 18 || cursor == 8 || cursor == 12) { SetForegroundWindow(handle); keyboardSim.MouseButtonDown(); keyboardSim.MouseButtonUp(); keyboardSim.MouseButtonDown(); keyboardSim.MouseButtonUp(); Thread.Sleep(1000); keyboardSim.KeyDown(loot); keyboardSim.KeyUp(loot); found = true; } else if (cursor == 13 || cursor == 11) { SetForegroundWindow(handle); keyboardSim.MouseButtonDown(); keyboardSim.MouseButtonUp(); keyboardSim.MouseButtonDown(); keyboardSim.MouseButtonUp(); Thread.Sleep(3000); keyboardSim.KeyDown(loot); keyboardSim.KeyUp(loot); found = true; } Thread.Sleep(1); if (found) { break; } } if (found) { break; } } Cursor.Position = new Point(X, Y); SetForegroundWindow(activeWindow); }