如何模拟键盘输入

        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 消息。  
SpxImage6_thumb%5B2%5D.jpg

转载于:https://www.cnblogs.com/zbqy/archive/2007/02/11/647710.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值