最近在玩一个网络游戏.但是里面老是要不停的按一个键加血.所以我想写个程序把这个步骤省掉.但是我写的测试程序老卡死了.是不是sendkeys.send不能离开当前窗口.失去焦点就没有办法了?
那用User32.dll里面的keybd_event可以么?但是我发现C#里面keybd_event有问题...
MSDN里面写的
VOID keybd_event( 
    BYTE bVk,
    BYTE bScan,
    DWORD dwFlags,
    PTR dwExtraInfo
);
通过不了我改成了如下这样:public static extern void keybd_event(byte bVk,byte bScan,int dwFlags,int dwExtraInfo);但是我运行这个BUTTON的点击的时候。TEXTBOX里面出现两个a 
private void button1_Click(object sender, System.EventArgs e)
{
    textBox1.Focus();
    keybd_event(0x41,0,0,0);
    keybd_event(0x41,0,1,0);
{
c#的keybd_event();里面应该怎么写。
我这个方法虽然可以实现模拟键盘输入了。但是不管怎么样都是一次按键。不能实现组合键
重要的还是这个代码要怎么写.完整的代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Timers;namespace 写着玩
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Timers.Timer timerClock = new System.Timers.Timer(); 
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
// 
// textBox1
// 
this.textBox1.Location = new System.Drawing.Point(112, 56);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
// 
// button1
// 
this.button1.Location = new System.Drawing.Point(104, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 24);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{ timerClock.Elapsed += new ElapsedEventHandler(OnTimer);
timerClock.Interval = 3000;
this.timerClock.Enabled=true;
} public void OnTimer( Object source, ElapsedEventArgs e )
{
 SendKeys.Send("a");
} }
}
希望大虾能给我仔细讲解,最好能有代码提供,因为我刚刚学程序设计才一个月.什么都不懂.谢谢了!
小弟在此感谢!