Advertisement
zefie

autostart WS4000

Jun 8th, 2023 (edited)
1,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Drawing;
  4. using System.Runtime.InteropServices;
  5. using System.Threading;
  6. using System.Windows.Forms;
  7.  
  8. namespace WindowsFormsApp1
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.  
  13.         public struct Rect
  14.         {
  15.             public int Left { get; set; }
  16.             public int Top { get; set; }
  17.             public int Right { get; set; }
  18.             public int Bottom { get; set; }
  19.         }
  20.         public Form1()
  21.         {
  22.             doCommands();
  23.             this.WindowState = FormWindowState.Minimized;
  24.         }
  25.  
  26.         private static void doCommands()
  27.         {
  28.             // Get application's directory
  29.             string path = System.IO.Path.GetDirectoryName(
  30.               System.Windows.Forms.Application.ExecutablePath);
  31.  
  32.             // launch WS4000v4.exe from application directory
  33.             Process p = Process.Start(path + "\\WS4000v4.exe");
  34.             p.WaitForInputIdle();
  35.  
  36.             // Get handle for the WS4000 Sim process.
  37.             // Iterating through every process is required unless we know
  38.             // the exact Window title, which can change per version.
  39.  
  40.             IntPtr hWnd = IntPtr.Zero;
  41.             foreach (Process pList in Process.GetProcesses())
  42.             {
  43.                 if (pList.MainWindowTitle.Contains("WS4000 Simulator Public Beta"))
  44.                 {
  45.                     hWnd = pList.MainWindowHandle;
  46.                 }
  47.             }
  48.  
  49.             // Get the screen position of WS4000
  50.             Rect WSRect = new Rect();
  51.             GetWindowRect(hWnd, ref WSRect);
  52.  
  53.             // Bring WS4000 to the front
  54.             SetForegroundWindow(hWnd);
  55.  
  56.             // Send the "F8" key to the application 10 times.
  57.             for (int i = 0; i<10; i++)
  58.             {
  59.                 SendKeys.SendWait("F8");
  60.                 Thread.Sleep(250);
  61.                 i++;
  62.             }
  63.             Thread.Sleep(1000);
  64.  
  65.             /* MouseHook.cs: https://pastebin.com/k3HfUeA7 */
  66.             // Move the cursor to the "Simulator" menu.
  67.             MouseHook.MoveMouse(new Point(WSRect.Left + 100, WSRect.Top + 60));
  68.             Thread.Sleep(250);
  69.  
  70.             // Click the "Simulator" menu, opening it
  71.             MouseHook.SendClick();
  72.             Thread.Sleep(250);
  73.  
  74.             // Move cursor down a bit, to the "Start Simulation" option
  75.             MouseHook.MoveMouse(new Point(WSRect.Left + 100, WSRect.Top + 80));
  76.             Thread.Sleep(250);
  77.  
  78.             // Click it
  79.             MouseHook.SendClick();
  80.             Thread.Sleep(250);
  81.  
  82.             // Close this application
  83.             Environment.Exit(0);
  84.         }
  85.  
  86.         [DllImport("User32.dll")]
  87.         static extern int SetForegroundWindow(IntPtr point);
  88.  
  89.         [DllImport("user32.dll")]
  90.         public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);
  91.     }
  92. }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement