Exemple #1
0
 public override void Press()
 {
     InputSimulator.SimulateTextEntry(_stringToSimulate);
     base.Press();
 }
 public void EnterText(string text)
 {
     InputSimulator.SimulateTextEntry(text);
 }
        static void SendMediaCenterCommand(MCCommands cmd)
        {
            switch (cmd)
            {
            case MCCommands.Play:     // Ctrl Shift P
                InputSimulator.SimulateModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT }, VirtualKeyCode.VK_P);
                break;

            case MCCommands.Pause:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_P);
                break;

            case MCCommands.Stop:
                InputSimulator.SimulateModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT }, VirtualKeyCode.VK_S);
                break;

            case MCCommands.Ffw:
                InputSimulator.SimulateModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT }, VirtualKeyCode.VK_F);
                break;

            case MCCommands.Rew:
                InputSimulator.SimulateModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT }, VirtualKeyCode.VK_B);
                break;

            case MCCommands.SkipFwd:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_F);
                break;

            case MCCommands.SkipBack:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_B);
                break;

            case MCCommands.Record:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_R);
                break;

            case MCCommands.NavUp:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                break;

            case MCCommands.NavDown:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                break;

            case MCCommands.NavLeft:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.LEFT);
                break;

            case MCCommands.NavRight:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                break;

            case MCCommands.NavBack:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.BACK);
                break;

            case MCCommands.Menu:
                InputSimulator.SimulateKeyDown(VirtualKeyCode.LWIN);
                InputSimulator.SimulateKeyDown(VirtualKeyCode.MENU);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                InputSimulator.SimulateKeyUp(VirtualKeyCode.MENU);
                InputSimulator.SimulateKeyUp(VirtualKeyCode.LWIN);
                break;

            case MCCommands.Info:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_D);
                break;

            case MCCommands.DVDMenu:
                InputSimulator.SimulateModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT }, VirtualKeyCode.VK_M);
                break;

            case MCCommands.DVDAudio:
                InputSimulator.SimulateModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT }, VirtualKeyCode.VK_A);
                break;

            case MCCommands.OK:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                break;

            case MCCommands.Clear:

                break;

            case MCCommands.Enter:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                break;

            case MCCommands.VolUp:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VOLUME_UP);
                break;

            case MCCommands.VolDown:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VOLUME_DOWN);
                break;

            case MCCommands.VolMute:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VOLUME_MUTE);
                break;

            case MCCommands.ChanUp:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.PRIOR);
                break;

            case MCCommands.ChanDown:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.NEXT);
                break;

            case MCCommands.Num0:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_0);
                break;

            case MCCommands.Num1:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_1);
                break;

            case MCCommands.Num2:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_2);
                break;

            case MCCommands.Num3:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_3);
                break;

            case MCCommands.Num4:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_4);
                break;

            case MCCommands.Num5:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_5);
                break;

            case MCCommands.Num6:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_6);
                break;

            case MCCommands.Num7:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_7);
                break;

            case MCCommands.Num8:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_8);
                break;

            case MCCommands.Num9:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_9);
                break;

            case MCCommands.NumHash:
                InputSimulator.SimulateTextEntry("#");
                break;

            case MCCommands.NumStar:
                InputSimulator.SimulateKeyPress(VirtualKeyCode.MULTIPLY);
                break;

            case MCCommands.Text:

                break;

            case MCCommands.TextRed:

                break;

            case MCCommands.TextGreen:

                break;

            case MCCommands.TextYellow:

                break;

            case MCCommands.TextBlue:

                break;

            case MCCommands.Subtitles:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_U);
                break;

            case MCCommands.GotoLiveTV:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_T);
                break;

            case MCCommands.GotoGuide:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_G);
                break;

            case MCCommands.GotoRecTV:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_O);
                break;

            case MCCommands.GotoPictures:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_I);
                break;

            case MCCommands.GotoVideos:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_E);
                break;

            case MCCommands.GotoMusic:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_M);
                break;

            case MCCommands.GotoMovies:
                InputSimulator.SimulateModifiedKeyStroke(new [] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT }, VirtualKeyCode.VK_M);
                break;

            case MCCommands.GotoRadio:
                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_A);
                break;


            case MCCommands.GotoExtras:
                InputSimulator.SimulateModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT }, VirtualKeyCode.VK_R);
                break;

            case MCCommands.GreenButton:
                InputSimulator.SimulateKeyDown(VirtualKeyCode.LWIN);
                InputSimulator.SimulateKeyDown(VirtualKeyCode.MENU);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                InputSimulator.SimulateKeyUp(VirtualKeyCode.MENU);
                InputSimulator.SimulateKeyUp(VirtualKeyCode.LWIN);
                break;

            case MCCommands.Power:
                if (File.Exists(MEDIA_CENTER_PATH))
                {
                    System.Diagnostics.Process.Start(MEDIA_CENTER_PATH);
                }

                /*
                 *             SendKeyDown(VK.VK_MENU);
                 * SendKeyStroke(VK.VK_F4);
                 * SendKeyUp(VK.VK_MENU);
                 */
                break;
            }
        }
Exemple #4
0
        // ==========================================
        //  UTILITY
        // ==========================================

        public void SimulateTextEntry(String text)
        {
            InputSimulator.SimulateTextEntry(text);
        }
Exemple #5
0
        private void trimData()
        {
            Timer.Reset();
            Timer.Start();
            string[] files = Directory.GetFiles("C:\\Diplomarbeit_Geoelektrik\\daten_mit_topography\\");
            Process  p     = checkForProcess("RES2DINV_3.59.118");

            if (p == null)
            {
                p = Process.Start("C:\\Diplomarbeit_Geoelektrik\\daten von usb-stick\\RES2DINV_3.59.118.exe");
            }
            try
            {
                Thread.Sleep(500);
                IntPtr res2dHandle = p.MainWindowHandle;
                ShowWindow(res2dHandle, SW_MAXIMIZE);                                                  //show window maximized

                SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "System Resources", 5)); //set focus to start dialog and wait for it
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                //change settings: read inversion parameters from .inv
                InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                InputSimulator.SimulateTextEntry("C:\\Diplomarbeit_Geoelektrik\\daten von usb-stick\\Gresten Modelblock-fix.ivp");
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                for (int i = CurrentFile; i < files.Length; i++) //run through all files in given directory from startAtFile to endAtFile
                {
                    if (!Timer.IsRunning)
                    {
                        Timer.Reset();
                        Timer.Start();
                    }
                    TaskbarProgress.SetValue(MainHandle, CurrentFile, files.Length - 1); //progress on taskbar
                    if (i % 6 == 0 && restart)
                    {
                        throw new RestartException(i);
                    }
                    else
                    {
                        restart = true;
                    }

                    if (StopAtNext)
                    {
                        StopAtNext = false;
                        ManageBot.Abort();
                        Stop(false);
                    }
                    MyConsole.WriteLine("#" + i + " started.");

                    //files to be saved
                    string invfilename = SAVETOINV + files[i].Split('.')[0].Split('\\').Last() + ".inv"; //Split for filename and add .inv
                    string datfilename = SAVETOTRIM + files[i].Split('\\').Last();                       //Split for filename

                    //if already exist, delete
                    if (File.Exists(invfilename))
                    {
                        MyConsole.WriteLine("#" + i + " (" + invfilename.Split('\\').Last() + ") existed, so it was removed.");
                        File.Delete(invfilename);
                    }
                    if (File.Exists(datfilename))
                    {
                        Console.WriteLine("#" + i + " (" + datfilename.Split('\\').Last() + ") existed, so it was removed.");
                        File.Delete(datfilename);
                    }

                    //read .dat file
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SleepHelper.WaitForWindow(BASIC_INTERVAL, "Input 2D resistivity data file", 5);
                    InputSimulator.SimulateTextEntry(files[i]);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    if (SleepHelper.CheckForWindow(new string[] { "Data Error", "Convergence Warning" }))
                    {
                        MyConsole.WriteLine("#" + i + " skipped due to error.");
                        CurrentFile = i + 1;
                        Properties.Settings.Default.progress = i + 1;
                        Properties.Settings.Default.Save();
                        throw new NotIntendedException(i, "Data Error or RMS error too high.");
                    }
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    /*SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Incomplete Gauss-Newton method", 5));
                     * Thread.Sleep(150);
                     * //check
                     * if (!SleepHelper.GetActiveWindowTitle().Contains("Incomplete Gauss-Newton method"))
                     * {
                     *  throw new NotIntendedException(i, "Read .dat file");
                     * }*/
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    //least squares inversion
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(1000);
                    SleepHelper.WaitForWindow(BASIC_INTERVAL, "File Name for Inversion Results", 5);
                    InputSimulator.SimulateTextEntry(invfilename);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Enter Additional Iterations", 1400));
                    if (SleepHelper.CheckForWindow(new string[] { "Data Error", "Convergence Warning" }))
                    {
                        MyConsole.WriteLine("#" + i + " skipped due to error.");
                        CurrentFile = i + 1;
                        Properties.Settings.Default.progress = i + 1;
                        Properties.Settings.Default.Save();
                        throw new NotIntendedException(i, "Data Error or RMS error too high.");
                    }
                    InputSimulator.SimulateTextEntry("0");
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(150);
                    SleepHelper.WaitForCursor(BASIC_INTERVAL, Cursors.Arrow); //window has a slight delay
                    Thread.Sleep(150);

                    //check if everything went right
                    if (!File.Exists(invfilename))
                    {
                        throw new NotIntendedException(i, "Least squares inversion: File not generated");
                    }

                    //display - show results
                    Thread.Sleep(150);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    //edit data - rms statistics
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    IntPtr test2 = SleepHelper.WaitForWindow(BASIC_INTERVAL, "RMS Error Analysis Window", 5);
                    SetForegroundWindow(test2);
                    Thread.Sleep(300);

                    //check if everything went right
                    if (!SleepHelper.GetActiveWindowTitle().Contains("RMS Error Analysis Window"))
                    {
                        throw new NotIntendedException(i, "Edit data - RMS statistics");
                    }

                    for (int redo = 0; redo < 26; redo++)
                    {
                        InputSimulator.SimulateKeyPress(VirtualKeyCode.LEFT);
                        Thread.Sleep(10);
                    }

                    //trim data
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN); //exit
                    Thread.Sleep(30);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Trim data set", 5));
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN); //trim data?
                    Thread.Sleep(30);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN); //to trim you need to save
                    Thread.Sleep(100);
                    ShowWindow(res2dHandle, SW_MINIMIZE);                   //minimize maximize, to work around a bug (otherwise filesave dialog does not appear)
                    Thread.Sleep(250);
                    ShowWindow(res2dHandle, SW_MAXIMIZE);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Output edited data file", 5));
                    InputSimulator.SimulateTextEntry(datfilename);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    Thread.Sleep(1000); //file needs some time until it is saved
                    //check if everything is right
                    if (!File.Exists(datfilename))
                    {
                        throw new NotIntendedException(i, "Trim data: File not generated");
                    }

                    //close display window
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT); //change output path? NO. (sometimes not needed)
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    MyConsole.WriteLine("#" + i + " finished.");
                    //update progress
                    CurrentFile = i + 1;
                    Properties.Settings.Default.progress = i + 1; //progress in settings
                    Properties.Settings.Default.Save();
                    Timer.Stop();
                    TimeIntervals.Add(Timer.ElapsedMilliseconds);
                }
            }
            catch (RestartException rsexc)
            {
                restart = false;
                MyConsole.WriteLine(rsexc);
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
            catch (ThreadAbortException taexc)
            {
                restart = false;
                MyConsole.WriteLine("#" + Properties.Settings.Default.progress + ": Trimbot aborted.");
                Timer.Stop();
            }
            catch (NotIntendedException niexc)
            {
                restart = false;
                MyConsole.WriteLine(niexc);
                Crashes++;
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
            catch (Exception exc)
            {
                restart = false;
                MyConsole.WriteLine("#" + Properties.Settings.Default.progress + ":\n" + exc);
                Crashes++;
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
        }
Exemple #6
0
        private void createxyz()
        {
            Timer.Reset();
            Timer.Start();
            string[] files = Directory.GetFiles("C:\\Diplomarbeit_Geoelektrik\\daten_trimmed\\");
            Process  p     = checkForProcess("RES2DINV_3.59.118");

            if (p == null)
            {
                p = Process.Start("C:\\Diplomarbeit_Geoelektrik\\daten von usb-stick\\RES2DINV_3.59.118.exe");
            }
            try
            {
                Thread.Sleep(500);
                IntPtr res2dHandle = p.MainWindowHandle;
                ShowWindow(res2dHandle, SW_MAXIMIZE);                                                  //show window maximized

                SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "System Resources", 5)); //set focus to start dialog and wait for it
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                //change settings: read inversion parameters from .inv
                InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                InputSimulator.SimulateTextEntry("C:\\Diplomarbeit_Geoelektrik\\daten von usb-stick\\Gresten Modelblock-fix.ivp");
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                for (int i = CurrentFile; i < files.Length; i++) //run through all files in given directory from startAtFile to endAtFile
                {
                    if (!Timer.IsRunning)
                    {
                        Timer.Reset();
                        Timer.Start();
                    }
                    TaskbarProgress.SetValue(MainHandle, CurrentFile, files.Length - 1); //progress on taskbar

                    if (StopAtNext)
                    {
                        StopAtNext = false;
                        ManageBot.Abort();
                        Stop(false);
                    }
                    MyConsole.WriteLine("#" + i + " started.");

                    //files to be saved
                    string invtrimfilename = SAVETOTRIMINV + files[i].Split('.')[0].Split('\\').Last() + ".inv"; //Split for filename and add .inv
                    string xyzfilename     = SAVETOXYZ + files[i].Split('.')[0].Split('\\').Last() + ".xyz";     //Split for filename and add .xyz

                    //if already exist, delete
                    if (File.Exists(invtrimfilename))
                    {
                        MyConsole.WriteLine("#" + i + " (" + invtrimfilename.Split('\\').Last() + ") existed, so it was removed.");
                        File.Delete(invtrimfilename);
                    }
                    if (File.Exists(xyzfilename))
                    {
                        Console.WriteLine("#" + i + " (" + xyzfilename.Split('\\').Last() + ") existed, so it was removed.");
                        File.Delete(xyzfilename);
                    }

                    //read .dat file
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SleepHelper.WaitForWindow(BASIC_INTERVAL, "Input 2D resistivity data file", 5);
                    InputSimulator.SimulateTextEntry(files[i]);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    if (SleepHelper.CheckForWindow(new string[] { "Data Error", "Convergence Warning" }))
                    {
                        MyConsole.WriteLine("#" + i + " skipped due to error.");
                        CurrentFile = i + 1;
                        Properties.Settings.Default.progress = i + 1;
                        Properties.Settings.Default.Save();
                        throw new NotIntendedException(i, "Data Error or RMS error too high.");
                    }
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    //least squares inversion
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "File Name for Inversion Results", 5));
                    Thread.Sleep(1500);
                    InputSimulator.SimulateTextEntry(invtrimfilename);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Enter Additional Iterations", 2000));
                    if (SleepHelper.CheckForWindow(new string[] { "Data Error", "Convergence Warning" }))
                    {
                        MyConsole.WriteLine("#" + i + " skipped due to error.");
                        CurrentFile = i + 1;
                        Properties.Settings.Default.progress = i + 1;
                        Properties.Settings.Default.Save();
                        throw new NotIntendedException(i, "Data Error or RMS error too high.");
                    }
                    InputSimulator.SimulateTextEntry("0");
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(150);
                    SleepHelper.WaitForCursor(BASIC_INTERVAL, Cursors.Arrow); //window has a slight delay
                    Thread.Sleep(150);

                    //check if everything went right
                    if (!File.Exists(invtrimfilename))
                    {
                        throw new NotIntendedException(i, "Least squares inversion: File not generated");
                    }

                    //display - show results
                    Thread.Sleep(150);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    //save xyz
                    Thread.Sleep(2000);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Choose iteration number", 5));
                    Thread.Sleep(150);
                    if (!SleepHelper.CheckForWindow(new string[] { "Choose iteration number" }))
                    {
                        throw new NotIntendedException(i, "Iteration number selection failed");
                    }

                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(150);
                    InputSimulator.SimulateTextEntry(xyzfilename);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    if (!SleepHelper.CheckForWindow(new string[] { "Message" }))
                    {
                        throw new NotIntendedException(i, "Save .xyz: No Message Window");
                    }

                    //close display window
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    Thread.Sleep(1000); //file needs some time until it is saved
                    //check if everything is right
                    if (!File.Exists(xyzfilename))
                    {
                        throw new NotIntendedException(i, "Save .xyz: File not generated");
                    }

                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT); //change output path? NO. (sometimes not needed)
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    MyConsole.WriteLine("#" + i + " finished.");
                    //update progress
                    CurrentFile = i + 1;
                    Properties.Settings.Default.progress = i + 1; //progress in settings
                    Properties.Settings.Default.Save();
                    Timer.Stop();
                    TimeIntervals.Add(Timer.ElapsedMilliseconds);

                    throw new RestartException(i);
                }
            }
            catch (RestartException rsexc)
            {
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
            catch (NotIntendedException niexc)
            {
                MyConsole.WriteLine(niexc);
                Crashes++;
                p.Kill();
                p.Close();
                TrimBot.Abort();
            } catch (ThreadAbortException taexc)
            {
                MyConsole.WriteLine("#" + Properties.Settings.Default.progress + ": Trimbot aborted.");
                Timer.Stop();
            }
            catch (Exception exc)
            {
                MyConsole.WriteLine("#" + Properties.Settings.Default.progress + ":\n" + exc);
                Crashes++;
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
        }
 void HandleInput(string key)
 {
     InputSimulator.SimulateTextEntry(key);
     newCharacter = (caps) ? key.ToUpper() : key;
 }
        private void KeyboardAction(string command, string keys) //executes the code line by line.
        {
            string         keyboardkey = keys.ToUpper();
            VirtualKeyCode code;

            try
            {
                switch (command)
                {
                case "DEFAULT_DELAY":
                case "DEFAULTDELAY":
                    defaultdelay       = true;
                    defaultdelayvalue += Convert.ToInt32(keys);
                    break;

                case "DELAY":
                    CheckDefaultSleep();
                    Thread.Sleep(Convert.ToInt32(keys));
                    break;

                case "STRING":
                    CheckDefaultSleep();
                    if (isCapsEnabled == true)
                    {
                        InputSimulator.SimulateTextEntry((keys.ToUpper()));
                    }
                    else
                    {
                        InputSimulator.SimulateTextEntry(keys);
                    }
                    break;

                case "WINDOWS":
                case "GUI":
                    CheckDefaultSleep();
                    if (keyboardkey.Length > 0)
                    {
                        if (Enum.TryParse <VirtualKeyCode>("VK_" + keyboardkey, out code))
                        {
                            InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.LWIN, code);
                        }
                    }
                    else
                    {
                        InputSimulator.SimulateKeyPress(VirtualKeyCode.LWIN);
                    }

                    break;

                case "ENTER":
                    CheckDefaultSleep();
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    break;

                case "APP":
                case "MENU":
                    CheckDefaultSleep();
                    InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.SHIFT, VirtualKeyCode.F10);
                    break;

                case "SHIFT":
                    CheckDefaultSleep();
                    switch (keys)
                    {
                    case "WINDOWS":
                    case "GUI":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.SHIFT, VirtualKeyCode.LWIN);
                        break;

                    case "UPARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.SHIFT, VirtualKeyCode.UP);
                        break;

                    case "DOWNARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.SHIFT, VirtualKeyCode.DOWN);
                        break;

                    case "LEFTARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.SHIFT, VirtualKeyCode.LEFT);
                        break;

                    case "RIGHTARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.SHIFT, VirtualKeyCode.RIGHT);
                        break;

                    default:
                        if (Enum.TryParse <VirtualKeyCode>("" + keyboardkey, out code))
                        {
                            InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.SHIFT, code);
                        }
                        break;
                    }

                    break;

                case "ALT":
                    CheckDefaultSleep();
                    switch (keys)
                    {
                    case "WINDOWS":
                    case "GUI":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.LMENU, VirtualKeyCode.LWIN);
                        break;

                    case "UPARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.LMENU, VirtualKeyCode.UP);
                        break;

                    case "DOWNARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.LMENU, VirtualKeyCode.DOWN);
                        break;

                    case "LEFTARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.LMENU, VirtualKeyCode.LEFT);
                        break;

                    case "RIGHTARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.LMENU, VirtualKeyCode.RIGHT);
                        break;

                    default:
                        if (keyboardkey.Length > 1)
                        {
                            //For support for keys such as "end"
                            if (Enum.TryParse <VirtualKeyCode>("" + keyboardkey, out code))
                            {
                                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.LMENU, code);
                            }
                        }
                        else
                        {
                            if (Enum.TryParse <VirtualKeyCode>("VK_" + keyboardkey, out code))
                            {
                                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.LMENU, code);
                            }
                        }
                        break;
                    }
                    break;

                case "CONTROL":
                case "CTRL":
                    CheckDefaultSleep();
                    switch (keys)
                    {
                    case "ESC":
                    case "ESCAPE":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.ESCAPE);
                        break;

                    case "PAUSE":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.PAUSE);
                        break;

                    case "UPARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.UP);
                        break;

                    case "DOWNARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.DOWN);
                        break;

                    case "LEFTARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.LEFT);
                        break;

                    case "RIGHTARROW":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.RIGHT);
                        break;

                    case "SHIFT":
                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT);
                        break;

                    default:
                        if (keyboardkey.Length > 1)
                        {
                            //For support for keys such as "end"
                            if (Enum.TryParse <VirtualKeyCode>("" + keyboardkey, out code))
                            {
                                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, code);
                            }
                        }
                        else
                        {
                            if (Enum.TryParse <VirtualKeyCode>("VK_" + keyboardkey, out code))
                            {
                                InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, code);
                            }
                        }
                        break;
                    }
                    break;

                case "TAB":
                    CheckDefaultSleep();
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.TAB);
                    break;

                case "DOWNARROW":
                case "DOWN":
                    CheckDefaultSleep();
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    break;

                case "LEFTARROW":
                case "LEFT":
                    CheckDefaultSleep();
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.LEFT);
                    break;

                case "RIGHTARROW":
                case "RIGHT":
                    CheckDefaultSleep();
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    break;

                case "UPARROW":
                case "UP":
                    CheckDefaultSleep();
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                    break;

                case "REPLAY":
                    CheckDefaultSleep();
                    for (int i = 0; i < Convert.ToInt32(keys); i++)
                    {
                        KeyboardAction(lastCommand, lastKey);
                    }
                    break;

                case "DELETE":
                    CheckDefaultSleep();
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DELETE);
                    break;

                case "CAPS":
                    CheckDefaultSleep();
                    isCapsEnabled = !isCapsEnabled;
                    break;

                case "SPACE":
                    CheckDefaultSleep();
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.SPACE);
                    break;

                case "PRINTSCREEN":
                    CheckDefaultSleep();
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.PRINT);
                    break;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error while trying to simulate keys. Probably UAC getting in the way. " +
                                "This toolkit cannot type when UAC is open for security reasons, try disabling UAC and running the script again ");
            }
            if (command != "REPLAY" && command != "REM") //If the last function wasn't replay/rem. Make the current command the last one
            {
                setLastCommand(command, keys);           //Used for the repeat function
            }
        }