I'm trying to open a notepad instance and write a virtual text entry to it. The notepad opens securely but nothing is written on it. What would be the problem and why?
using System;
using System.Diagnostics;
using WindowsInput;
using WindowsInput.Native;
class Program
{
static void Main()
{
try
{
Process notepadProcess = new Process();
notepadProcess.StartInfo.FileName = "notepad.exe";
notepadProcess.Start();
InputSimulator simulator = new InputSimulator();
simulator.Keyboard.TextEntry("This is a message that will be written to Notepad");
}
catch (Exception ex)
{
Console.WriteLine("Error opening Notepad: " + ex.Message);
}
}
}
I tried to pause the execution thread to allow time for the notepad to start, but I only managed to get it typed if I moved the mouse.