日期:2009-12-25  浏览次数:20602 次

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace _模拟键盘按键向文本框控件输入A_Z
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            // 文本框获取焦点
            this.textBox1.Focus();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 65; i < 91; i++)
            {
                // 设置键盘按键代码
                char Letter = (char)i;

                // 模拟键盘按键输入字母

                // 文本框获取焦点
                this.textBox1.Focus();

                SendKeys.Send(Letter.ToString()); // 暂停线程模拟按键速度

                System.Threading.Thread.Sleep(10); // 响应Windows消息等待下次按键

                SendKeys.Flush();
            }
        }
    }
}