zefie icon

autostart WS4000

zefie | PRO | 06/11/23 03:05:26 PM UTC (Edited) | 0 ⭐ | 1617 👁️ | Never ⏰ | []
C# |

2.76 KB

|

None

|

0 👍

/

0 👎

using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
 
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
 
        public struct Rect
        {
            public int Left { get; set; }
            public int Top { get; set; }
            public int Right { get; set; }
            public int Bottom { get; set; }
        }
        public Form1()
        {
            doCommands();
            this.WindowState = FormWindowState.Minimized;
        }
 
        private static void doCommands()
        {
            // Get application's directory
            string path = System.IO.Path.GetDirectoryName(
              System.Windows.Forms.Application.ExecutablePath);
 
            // launch WS4000v4.exe from application directory
            Process p = Process.Start(path + "\\WS4000v4.exe");
            p.WaitForInputIdle();
 
            // Get handle for the WS4000 Sim process.
            // Iterating through every process is required unless we know
            // the exact Window title, which can change per version.
 
            IntPtr hWnd = IntPtr.Zero;
            foreach (Process pList in Process.GetProcesses())
            {
                if (pList.MainWindowTitle.Contains("WS4000 Simulator Public Beta"))
                {
                    hWnd = pList.MainWindowHandle;
                }
            }
 
            // Get the screen position of WS4000
            Rect WSRect = new Rect();
            GetWindowRect(hWnd, ref WSRect);
 
            // Bring WS4000 to the front
            SetForegroundWindow(hWnd);
 
            // Send the "F8" key to the application 10 times.
            for (int i = 0; i<10; i++)
            {
                SendKeys.SendWait("F8");
                Thread.Sleep(250);
                i++;
            }
            Thread.Sleep(1000);
 
            /* MouseHook.cs: https://pastebin.com/k3HfUeA7 */
            // Move the cursor to the "Simulator" menu.
            MouseHook.MoveMouse(new Point(WSRect.Left + 100, WSRect.Top + 60));
            Thread.Sleep(250);
 
            // Click the "Simulator" menu, opening it
            MouseHook.SendClick();
            Thread.Sleep(250);
 
            // Move cursor down a bit, to the "Start Simulation" option
            MouseHook.MoveMouse(new Point(WSRect.Left + 100, WSRect.Top + 80));
            Thread.Sleep(250);
 
            // Click it
            MouseHook.SendClick();
            Thread.Sleep(250);
 
            // Close this application
            Environment.Exit(0);
        }
 
        [DllImport("User32.dll")]
        static extern int SetForegroundWindow(IntPtr point);
 
        [DllImport("user32.dll")]
        public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);
    }
}
 

Comments