Beispiel #1
0
 /**<summary>Moves the mouse and clicks for a duration.</summary>*/
 public static void SimulateClick(int x, int y, int duration)
 {
     MoveMouse(x, y);
     CppImports.MouseDown();
     Thread.Sleep(duration);
     CppImports.MouseUp();
 }
Beispiel #2
0
        //============ CHECKS ============
        #region Checks

        /**<summary>Updates the info on the Terraria window.</summary>*/
        public static bool Update(bool fullUpdate)
        {
            try {
                if (fullUpdate)
                {
                    process = null;
                    string[] exeNames = Config.ExecutableNames.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < exeNames.Length && process == null; i++)
                    {
                        if (!string.IsNullOrWhiteSpace(exeNames[i]))
                        {
                            process = Process.GetProcessesByName(exeNames[i]).FirstOrDefault();
                        }
                    }
                }
                if (process != null)
                {
                    clientArea = CppImports.GetClientArea(process.MainWindowHandle);
                    focus      = CppImports.WindowHasFocus(process.MainWindowHandle);
                    return(clientArea != new Rect(0, 0, 0, 0));
                }
            }
            catch (Exception) { }

            clientArea = new Rect(0, 0, 0, 0);
            focus      = false;
            return(false);
        }
        //============ CHECKS ============
        #region Checks

        /**<summary>Updates the info on the Terraria window.</summary>*/
        public static bool Update(bool fullUpdate)
        {
            try {
                if (fullUpdate)
                {
                    process = Process.GetProcessesByName(Config.ExecutableName).FirstOrDefault();
                }
                if (process != null)
                {
                    clientArea = CppImports.GetClientArea(process.MainWindowHandle);
                    focus      = CppImports.WindowHasFocus(process.MainWindowHandle);
                    return(clientArea != new Rect(0, 0, 0, 0));
                }
            }
            catch (Exception) { }

            clientArea = new Rect(0, 0, 0, 0);
            focus      = false;
            return(false);
        }
        //https://stackoverflow.com/questions/2315561/correct-way-in-net-to-switch-the-focus-to-another-application?answertab=oldest#tab-top
        /**<summary>Focuses on the Terraria Window.</summary>*/
        public static bool Focus()
        {
            try {
                if (process != null)
                {
                    // The window is hidden so try to restore it before setting focus.
                    CppImports.RestoreFromMinimzied(process.MainWindowHandle);

                    // Set user the focus to the window
                    CppImports.FocusWindow(process.MainWindowHandle);

                    // Reacquire the client rect
                    clientArea = CppImports.GetClientArea(process.MainWindowHandle);
                    focus      = CppImports.WindowHasFocus(process.MainWindowHandle);
                    return(clientArea != new Rect(0, 0, 0, 0));
                }
                return(false);
            }
            catch (Exception) {
                return(false);
            }
        }
Beispiel #5
0
 /**<summary>Releases the mouse.</summary>*/
 public static void MouseUp()
 {
     CppImports.MouseUp();
 }
Beispiel #6
0
 /**<summary>Presses the mouse down.</summary>*/
 public static void MouseDown()
 {
     CppImports.MouseDown();
 }
Beispiel #7
0
 /**<summary>Clicks the mouse.</summary>*/
 public static void MouseClick()
 {
     CppImports.MouseDown();
     CppImports.MouseUp();
 }
Beispiel #8
0
        //=========== STRINGS ============
        #region Strings

        /**<summary>Gets the human-readable string of the keybind.</summary>*/
        public string ToProperString()
        {
            if (Key == Key.None)
            {
                return("<No Keybind>");
            }

            System.Windows.Forms.Keys formsKey = (System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey(Key);
            string displayString = "";

            if (Modifiers.HasFlag(ModifierKeys.Control))
            {
                formsKey      |= System.Windows.Forms.Keys.Control;
                displayString += "Ctrl+";
            }
            if (Modifiers.HasFlag(ModifierKeys.Shift))
            {
                formsKey      |= System.Windows.Forms.Keys.Shift;
                displayString += "Shift+";
            }
            if (Modifiers.HasFlag(ModifierKeys.Alt))
            {
                formsKey      |= System.Windows.Forms.Keys.Alt;
                displayString += "Alt+";
            }

            char mappedChar = Char.ToUpper(CppImports.GetCharFromKey(Key));

            if (Key >= Key.Multiply && Key <= Key.Divide && Key != Key.Separator)
            {
                switch (Key)
                {
                case Key.Multiply:      displayString += "NumPad*"; break;

                case Key.Add:           displayString += "NumPad+"; break;

                case Key.Subtract:      displayString += "NumPad-"; break;

                case Key.Decimal:       displayString += "NumPad."; break;

                case Key.Divide:        displayString += "NumPad/"; break;
                }
            }
            else if (Key >= Key.NumPad0 && Key <= Key.NumPad9)
            {
                displayString += Key.ToString();
            }
            else if (Key == Key.Pause)
            {
                displayString += "PauseBreak";
            }
            else if (mappedChar > 32)             // Yes, exclude space
            {
                displayString += mappedChar;
            }
            else if (Key == Key.Back)
            {
                displayString += "Backspace";
            }
            else if (Key == Key.System)
            {
                displayString += "Alt";
            }
            else
            {
                displayString += Key.ToString();
            }
            return(displayString);
        }