public static bool ActiveSwitches(VirtualKeyCode key, bool swappedPrayers)
        {
            bool swappedItems = false;
            foreach (var autoSwitchHotkey in Settings.Instance.ActiveAutoSwitchHotkeys)
            {
                var activeKey = LowLevelInput.Converters.KeyCodeConverter.ToVirtualKeyCode((int)autoSwitchHotkey.Key);
                if (activeKey != key) continue;
                swappedItems = true;
                // If we just swapped prayers, make a short delay
                if (swappedPrayers)
                {
                    Thread.Sleep(50);
                }

                if (Settings.Instance.ActiveAutoSwitchHotkeys != null)
                {
                    var oldPos = Cursor.Position;
                    foreach (var locations in autoSwitchHotkey.Value)
                    {
                        SendKeys.SendWait("{" + Settings.Instance.InventFKey + "}");
                        Thread.Sleep(10);
                        WindowsImports.SetCursorPos(Settings.Instance.InventorySlots[locations].X, Settings.Instance.InventorySlots[locations].Y);
                        WindowsImports.LeftMouseClick(Settings.Instance.InventorySlots[locations].X, Settings.Instance.InventorySlots[locations].Y);
                        Thread.Sleep(50);
                    }

                    if (Settings.Instance.ReturnToOldPos)
                    {
                        Mouse.LinearSmoothMove(oldPos, Settings.Instance.Speed, false);
                    }
                }
            }

            return swappedItems;
        }
Exemplo n.º 2
0
        public static void LinearSmoothMove(Point newPosition, int steps, bool click)
        {
            Point  start     = Cursor.Position;
            PointF iterPoint = start;

            //Randomize End position to not click at same coords multiple times
            newPosition = GetRandomizedPoint(newPosition);

            // Find the slope of the line segment defined by start and newPosition
            PointF slope = new PointF(newPosition.X - start.X, newPosition.Y - start.Y);

            // Divide by the number of steps(Smooth value)
            slope.X = slope.X / steps;
            slope.Y = slope.Y / steps;

            // Move the mouse to each iterative point.
            for (int i = 0; i < steps; i++)
            {
                iterPoint = new PointF(iterPoint.X + slope.X, iterPoint.Y + slope.Y);
                Point roundedPoint = new Point(Convert.ToInt32(iterPoint.X), Convert.ToInt32(iterPoint.Y));
                WindowsImports.SetCursorPos(roundedPoint.X, roundedPoint.Y);
                //Natural delay in mouse movement
                Thread.Sleep(10);
            }
            // Move the mouse to the final destination.
            WindowsImports.SetCursorPos(newPosition.X, newPosition.Y);

            //Click at last position?
            Thread.Sleep(50);
            if (click)
            {
                WindowsImports.LeftMouseClick(newPosition.X, newPosition.Y);
            }
        }
Exemplo n.º 3
0
        private static void Start()
        {
            Console.Clear();
            if (Settings.Instance == null)
            {
                Console.WriteLine("Settings object was null, please load or set some settings");
                Console.WriteLine("Press any key to return to main menu");
                Console.ReadKey();
                return;
            }
            var bPrayerActive     = Settings.Instance.ActivePrayerHotkeys == null;
            var bAutoSwitchActive = Settings.Instance.ActiveAutoSwitchHotkeys == null;
            var bAutoSpecActive   = Settings.Instance.SpecialAttackHotkeys == null;

            if (bPrayerActive && bAutoSwitchActive)
            {
                Console.WriteLine("Unable to start since no hotkeys were specified");
                Console.WriteLine("Press any key to return to main menu");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Mousespeed is: " + Settings.Instance.Speed);
            Console.WriteLine("Return to old pos: " + Settings.Instance.ReturnToOldPos);
            foreach (var autoSwitchHotkey in Settings.Instance.ActiveAutoSwitchHotkeys)
            {
                Console.WriteLine("Autoswitch on hotkey: " + autoSwitchHotkey.Key);
            }

            foreach (var prayerHotkey in Settings.Instance.ActivePrayerHotkeys)
            {
                Console.WriteLine(prayerHotkey.Key + " on hotkey " + prayerHotkey.Value);
            }

            foreach (var spec in Settings.Instance.SpecialAttackHotkeys)
            {
                Console.WriteLine("Special attack on hotkey: " + spec.Key);
            }
            Console.WriteLine("Press ESC to stop OSRS-AutoSwitcher");
            DateTime startTime = DateTime.Now;

            while (true)
            {
                Thread.Sleep(50);

                var resTime = DateTime.Now - startTime;
                Console.Write("Been running for: " + Math.Floor(resTime.TotalSeconds) + " seconds");
                Console.CursorLeft = 0;
                if (!bPrayerActive)
                {
                    foreach (var prayerHotkey in Settings.Instance.ActivePrayerHotkeys)
                    {
                        if (Convert.ToBoolean((long)WindowsImports.GetAsyncKeyState(prayerHotkey.Value) & 0x8000))
                        {
                            var oldPos = Cursor.Position;
                            SendKeys.SendWait("{" + Settings.Instance.PrayerFkey + "}");
                            Thread.Sleep(10);
                            Mouse.LinearSmoothMove(Settings.Instance.Prayers[prayerHotkey.Key], Settings.Instance.Speed, true);
                            if (Settings.Instance.ReturnToOldPos)
                            {
                                Mouse.LinearSmoothMove(oldPos, Settings.Instance.Speed, false);
                            }
                        }
                    }
                }

                if (!bAutoSwitchActive)
                {
                    foreach (var autoSwitchHotkey in Settings.Instance.ActiveAutoSwitchHotkeys)
                    {
                        if (Convert.ToBoolean((long)WindowsImports.GetAsyncKeyState(autoSwitchHotkey.Key) & 0x8000))
                        {
                            if (Settings.Instance.ActiveAutoSwitchHotkeys != null)
                            {
                                var oldPos = Cursor.Position;
                                foreach (var locations in autoSwitchHotkey.Value)
                                {
                                    SendKeys.SendWait("{" + Settings.Instance.InventFKey + "}");
                                    Thread.Sleep(10);
                                    WindowsImports.SetCursorPos(Settings.Instance.InventorySlots[locations].X,
                                                                Settings.Instance.InventorySlots[locations].Y);
                                    WindowsImports.LeftMouseClick(Settings.Instance.InventorySlots[locations].X,
                                                                  Settings.Instance.InventorySlots[locations].Y);
                                    Thread.Sleep(50);
                                }

                                if (Settings.Instance.ReturnToOldPos)
                                {
                                    Mouse.LinearSmoothMove(oldPos, Settings.Instance.Speed, false);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Autoswitch inventory settings was null, terminating...");
                                return;
                            }
                        }
                    }
                }

                if (!bAutoSpecActive)
                {
                    if (Settings.Instance.SpecialAttackHotkeys != null)
                    {
                        foreach (var hotkey in Settings.Instance.SpecialAttackHotkeys)
                        {
                            if (Convert.ToBoolean((long)WindowsImports.GetAsyncKeyState(hotkey.Key) & 0x8000))
                            {
                                var oldPos = Cursor.Position;
                                SendKeys.SendWait("{" + Settings.Instance.InventFKey + "}");
                                foreach (var specWep in hotkey.Value.InventoryId)
                                {
                                    Thread.Sleep(10);
                                    Mouse.LinearSmoothMove(new Point(
                                                               Settings.Instance.InventorySlots[specWep].X,
                                                               Settings.Instance.InventorySlots[specWep].Y),
                                                           Settings.Instance.Speed,
                                                           true);
                                    Thread.Sleep(10);
                                }

                                SendKeys.SendWait("{" + Settings.Instance.AttackFkey + "}");
                                Thread.Sleep(Settings.Instance.WaitForSpecBar ? 450 : 100);
                                Mouse.LinearSmoothMove(oldPos, Settings.Instance.Speed, true);
                                int pressedCounter = 0;
                                while (pressedCounter != hotkey.Value.SpecTimes)
                                {
                                    Mouse.LinearSmoothMove(Settings.Instance.SpecialAttackBarPoint,
                                                           Settings.Instance.Speed, true);
                                    Thread.Sleep(100);
                                    pressedCounter++;
                                }
                                Mouse.LinearSmoothMove(oldPos,
                                                       Settings.Instance.Speed, true);
                                if (Settings.Instance.ReturnToOldPos)
                                {
                                    Mouse.LinearSmoothMove(oldPos, Settings.Instance.Speed, false);
                                }
                            }
                        }
                    }

                    if (Convert.ToBoolean((long)WindowsImports.GetAsyncKeyState(Keys.Escape) & 0x0001))
                    {
                        break;
                    }
                }
            }
        }