Ejemplo n.º 1
0
        static void Main()
        {
            ConsoleHelper.WriteMessage("Virtual Autoclicker Console is starting!");

            VacEnvironment.Initialize();

            StartClosingHandlers();
            System.Console.Title = "Virtual Autoclicker";

            ConsoleHelper.WriteMessage("Virtual Autoclicker Console has started!");

            while (true)
            {
                if (System.Console.ReadKey(true).Key is ConsoleKey.Enter)
                {
                    System.Console.Write("VAC >> ");

                    var input = System.Console.ReadLine();

                    if (!string.IsNullOrWhiteSpace(input) && input.Length > 0)
                    {
                        CommandHandler.ParseCommand(
                            input.Split(' ')[0],
                            input.Split(' ').Length > 1 ? input.Split(' ').Skip(1).ToArray() : null
                            );
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts all handlers ensuring that the application closes the running autoclicker before exiting.
        /// </summary>
        public static void StartClosingHandlers()
        {
            System.Console.CancelKeyPress += (sender, e) =>
            {
                ConsoleHelper.WriteWarning("Application closing, running clean up!");
                e.Cancel = true;
                VacEnvironment.GetAcWorker()?.Picnic();
                Environment.Exit(0);
            };

            AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
            {
                VacEnvironment.GetAcWorker()?.Picnic();
            };
        }
Ejemplo n.º 3
0
        public static void ParseCommand(string commandValue, string[]?args)
        {
            if (string.IsNullOrWhiteSpace(commandValue))
            {
                return;
            }

            var acWorker = VacEnvironment.GetAcWorker();

            if (acWorker is null)
            {
                ConsoleHelper.WriteError("AutoClickerWorker was not properly initialized, please restart the application.");

                return;
            }

            try
            {
                Enum.TryParse <Commands>(commandValue, true, out var command);

                switch (command)
                {
                case Commands.Start:
                case Commands.Startautoclicker:
                {
                    if (args is null || args.Length <= 2)
                    {
                        ConsoleHelper.WriteWarning(
                            "Command usage: 'startautoclicker \"P\" X,Y I' please " +
                            "refer to the readme.md file for further assistance.");

                        break;
                    }

                    var processName = args[0];

                    // If the process name is put between double quotation marks
                    if (args[0].StartsWith('"') && args[0].EndsWith('"'))
                    {
                        var pattern = new Regex("\"(.*?)\"");
                        var matches = pattern.Matches(processName);
                        if (matches.Count > 0)
                        {
                            processName = matches[0].Groups[1].Value.Replace("\"", "");
                        }
                    }

                    var coordinates = new Coordinates
                    {
                        X = int.Parse(args[1].Split(',')[0]),
                        Y = int.Parse(args[1].Split(',')[1]),
                    };

                    StartAutoClicker(acWorker, processName, coordinates, int.Parse(args[2]));

                    break;
                }

                case Commands.Stop:
                case Commands.StopAutoClicker:
                case Commands.Picnic:
                {
                    Picnic(acWorker);

                    break;
                }

                case Commands.Unknown:
                //TODO do something regarding unknow commands.

                default:
                    ConsoleHelper.WriteWarning($"No command found named '{commandValue}'");

                    break;
                }
            }
            catch (Exception exception)
            {
                ConsoleHelper.WriteError($"Problem parsing or starting command '{commandValue}'", exception);
            }
        }