C#按键(键盘)通过字符串写一个特定的单词

C# Key press (keyboard) to write a specific word by a string

我想写一个简单的应用程序,从一个字符串中获取一个单词,然后按下该字符串中每个字母对应的键,来写那个单词,例如在记事本上。

到目前为止我得到的是:

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
    }
}

如何获得Keyboard.KeyPress活动?

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

}

我希望这有效!

如果我理解你的意思,你需要将你的字符串拆分成字母,然后定义 Keyboard.KeyIsPressed(OfEachLetter) 并创建一个 if 语句来显示按下的字母。使用 KeyDown 事件后。

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.: 愚蠢的程序员还没喝咖啡呢。 干杯