flaimme
flaimme

Reputation: 99

C# Write text to another program, from the background

Hello I am doing a program that will notice when a specific key is pressed and write an specific letter where the person is writing. I had thought of doing it in a Console app or should i do it in an Windows Forms? I don't either now how to get it to work in the background or how to to write it out where the user do write?

the code i have done until now looks like:

static void Main(string[] args)
    {
        while (true)
        {
            ConsoleKeyInfo cki;
            cki = Console.ReadKey();
            Console.WriteLine(cki.Key.ToString());

            if (cki.Key.ToString() == "F" && (cki.Modifiers & ConsoleModifiers.Control) != 0)
            {
                //typ something where the person is writing
            }
        }
    }

thanks for all help

Upvotes: 1

Views: 2122

Answers (1)

annonymously
annonymously

Reputation: 4708

If you add a reference to System.Windows.Forms then you can do this:

//outside namespace:
using TSendKeys = System.Windows.Forms.SendKeys;

//To type a key:
TSendKeys.Send("Put whatever you want here");

Upvotes: 2

Related Questions