如何模拟键盘输入
private void button1_Click(object sender, System.EventArgs e)
{//英文输入
this.richTextBox1.Focus();
for(int i=65;i<91;i++)
{
char Letter=(char)i;
SendKeys.Send(Letter.ToString());
System.Threading.Thread.Sleep(100);
SendKeys.Flush();
}
for(int i=97;i<123;i++)
{
char Letter=(char)i;
SendKeys.Send(Letter.ToString());
System.Threading.Thread.Sleep(100);
SendKeys.Flush();
}
}
private void button3_Click(object sender, System.EventArgs e)
{//数字输入
this.richTextBox1.Focus();
for(int i=0;i<10;i++)
{
SendKeys.Send(i.ToString());
System.Threading.Thread.Sleep(100);
SendKeys.Flush();
}
}
private void button4_Click(object sender, System.EventArgs e)
{//Backspace
this.richTextBox1.Focus();
SendKeys.Send("{Backspace}");
}
private void button5_Click(object sender, System.EventArgs e)
{//Home
this.richTextBox1.Focus();
SendKeys.Send("{Home}");
}
private void button6_Click(object sender, System.EventArgs e)
{//End
this.richTextBox1.Focus();
SendKeys.Send("{End}");
}
private void button7_Click(object sender, System.EventArgs e)
{//Enter
this.richTextBox1.Focus();
SendKeys.Send("{Enter}");
}
private void button8_Click(object sender, System.EventArgs e)
{//Delete
this.richTextBox1.Focus();
SendKeys.Send("{Delete}");
}
private void button2_Click(object sender, System.EventArgs e)
{//Shift+Home
this.richTextBox1.Focus();
SendKeys.Send("+{Home}");
}
private void button9_Click(object sender, System.EventArgs e)
{//Shift+End
this.richTextBox1.Focus();
SendKeys.Send("+{End}");
}
看下方法的说明
public class SendKeys : System.Object
System.Windows.Forms 的成员
摘要:
提供将键击发送到应用程序的方法。
public static void Send ( System.String keys )
System.Windows.Forms.SendKeys 的成员
摘要:
向活动应用程序发送击键。
public static void Sleep ( System.TimeSpan timeout )
System.Threading.Thread 的成员
摘要:
将当前线程阻塞指定的时间。
public static void Flush ( )
System.Windows.Forms.SendKeys 的成员
摘要:
处理消息队列中当前的所有 Windows 消息。