[英]C# Key press (keyboard) to write a specific word by a string
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?您将如何获得 Keyboard.KeyPress 事件?
public void TestKeyboard()
{
string a = "test";
foreach (char c in a)
{
System.Threading.Thread.Sleep(100);
SendKeys.Send(c.ToString());
}
}
I hope this works!我希望这有效!
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.如果我理解您的意思,您需要将您拥有的字符串拆分为字母,并定义
Keyboard.KeyIsPressed(OfEachLetter)
并创建一个 if 语句来显示按下的字母。 after using the KeyDown event.使用 KeyDown 事件后。
How do I split a word's letters into an Array in C#? 如何在 C# 中将单词的字母拆分为数组? http://csharp.net-informations.com/gui/key-press-cs.htm http://csharp.net-informations.com/gui/key-press-cs.htm
http://csharp.net-informations.com/gui/key-press-cs.htm http://csharp.net-informations.com/gui/key-press-cs.htm
PS: woosy programmer didn't have his coffee yet. PS:笨手笨脚的程序员还没喝咖啡呢。 Cheers
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.