【问题标题】:C# Key press (keyboard) to write a specific word by a stringC# Key press(键盘)通过字符串写入特定单词
【发布时间】:2021-03-05 22:02:52
【问题描述】:

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

到目前为止我得到的是:

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 事件?

【问题讨论】:

  • 这能回答你的问题吗? Simulating Key Press c#
  • @MathewHD 它没有回答我的问题。我想做的是从字符串中读取一个单词,然后使用按键逐个字母地“键入”该单词。

标签: c# string keyboard keypress


【解决方案1】:
public void TestKeyboard()
{
    string a = "test";
    foreach (char c in a)
    {
        System.Threading.Thread.Sleep(100);
        SendKeys.Send(c.ToString());
    }

}

我希望这行得通!

【讨论】:

    【解决方案2】:

    如果我理解您的意思,您需要将您拥有的字符串拆分为字母,并定义 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.htmhttp://csharp.net-informations.com/gui/key-press-cs.htm

    P.S.: woosy 程序员还没有喝咖啡。 干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 2019-02-06
      相关资源
      最近更新 更多