0

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.

1 Answer 1

1

If you cannot tell InputSimulator which process the text should be sent to, the focus must be set to the recipient notepadProcess (before sending). It should be noted that Notepad consists of a control for the menu and a control for the edit area. The focus of your text must be on the latter. You set this with your mouse click.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.