0

I wanted to write a simple application, to get a word from a string, and keypress the keys corresponding of each letter from that string, to write that word, for example on notepad.

What I got so far is:

public void TestKeyboard()
{
    string a = "test"; //this is the string it should be written
    foreach (char c in a)
    {
        Keyboard.KeyPress(c); //how to obtain this? this isn't working
    }
}

How would you obtain the Keyboard.KeyPress event?

  • Does this answer your question? [Simulating Key Press c#](https://stackoverflow.com/questions/3047375/simulating-key-press-c-sharp) – IndieGameDev Nov 23 '20 at 07:39
  • @MathewHD it does not answer my question. What I wanted to do is read a word from a string and "type" that word letter by letter using keypress. – Ferdinando Di Lauro Nov 23 '20 at 07:51

2 Answers2

0
public void TestKeyboard()
{
    string a = "test";
    foreach (char c in a)
    {
        System.Threading.Thread.Sleep(100);
        SendKeys.Send(c.ToString());
    }

}

I hope this works!

0

If I understood what you mean, you need to split the string you have into letters, and define the Keyboard.KeyIsPressed(OfEachLetter) and create an if statement to show the letter pressed. after using the KeyDown event.

How do I split a word's letters into an Array in C#? http://csharp.net-informations.com/gui/key-press-cs.htm http://csharp.net-informations.com/gui/key-press-cs.htm

P.S.: woosy programmer didn't have his coffee yet. Cheers