Winforms C#-SendKeys GUI按钮错误

Winforms C#-SendKeys GUI按钮错误,winforms,button,user-interface,timer,sendkeys,Winforms,Button,User Interface,Timer,Sendkeys,我从YouTube下载了一个垃圾短信程序,并对其进行了反编译。代码如下: using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; namespace SimpleSpammer { public class Form1 : Form { private IContainer components;

我从YouTube下载了一个垃圾短信程序,并对其进行了反编译。代码如下:

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

namespace SimpleSpammer
{
  public class Form1 : Form
  {
    private IContainer components;
    private TextBox textBox1;
    private Button button1;
    private Button button2;
    private Label label1;
    private LinkLabel linkLabel1;
    private Label label2;
    private LinkLabel linkLabel2;
    private Label label3;
    private Timer timer1;
    private Label label4;
    private TextBox textBox2;
    private Label label5;
    private CheckBox checkBox1;

    public Form1()
    {
      this.components = (IContainer) null;
      base.\u002Ector();
      this.InitializeComponent();
    }

    protected override void Dispose(bool disposing)
    {
      if (disposing && this.components != null)
        this.components.Dispose();
      base.Dispose(disposing);
    }

    private void InitializeComponent()
    {
      this.components = (IContainer) new Container();
      this.textBox1 = new TextBox();
      this.button1 = new Button();
      this.button2 = new Button();
      this.label1 = new Label();
      this.linkLabel1 = new LinkLabel();
      this.label2 = new Label();
      this.linkLabel2 = new LinkLabel();
      this.label3 = new Label();
      this.timer1 = new Timer(this.components);
      this.label4 = new Label();
      this.textBox2 = new TextBox();
      this.label5 = new Label();
      this.checkBox1 = new CheckBox();
      this.SuspendLayout();
      this.textBox1.Location = new Point(13, 13);
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new Size(259, 20);
      this.textBox1.TabIndex = 0;
      this.textBox1.Text = "SPAM !";
      this.textBox1.TextAlign = HorizontalAlignment.Center;
      this.button1.Location = new Point(13, 39);
      this.button1.Name = "button1";
      this.button1.Size = new Size(75, 23);
      this.button1.TabIndex = 1;
      this.button1.Text = "Start";
      this.button1.UseVisualStyleBackColor = true;
      // ISSUE: method pointer
      this.button1.Click += new EventHandler((object) this, __methodptr(button1_Click));
      this.button2.Location = new Point(197, 39);
      this.button2.Name = "button2";
      this.button2.Size = new Size(75, 23);
      this.button2.TabIndex = 2;
      this.button2.Text = "Stop";
      this.button2.UseVisualStyleBackColor = true;
      // ISSUE: method pointer
      this.button2.Click += new EventHandler((object) this, __methodptr(button2_Click));
      this.label1.AutoSize = true;
      this.label1.Font = new Font("Arial", 8.25f, FontStyle.Italic, GraphicsUnit.Point, (byte) 0);
      this.label1.ForeColor = SystemColors.WindowFrame;
      this.label1.Location = new Point(7, 216);
      this.label1.Name = "label1";
      this.label1.Size = new Size(275, 14);
      this.label1.TabIndex = 3;
      this.label1.Text = "Copyright © 2010 TheDarkJoker94. This is a freeware.";
      this.linkLabel1.AutoSize = true;
      this.linkLabel1.Location = new Point(30, 190);
      this.linkLabel1.Name = "linkLabel1";
      this.linkLabel1.Size = new Size(162, 13);
      this.linkLabel1.TabIndex = 4;
      this.linkLabel1.TabStop = true;
      this.linkLabel1.Text = "http://thedarkjoker94.cer33.com";
      // ISSUE: method pointer
      this.linkLabel1.LinkClicked += new LinkLabelLinkClickedEventHandler((object) this, __methodptr(linkLabel1_LinkClicked));
      this.label2.AutoSize = true;
      this.label2.Location = new Point(10, 135);
      this.label2.Name = "label2";
      this.label2.Size = new Size(172, 13);
      this.label2.TabIndex = 5;
      this.label2.Text = "Check my C# Tutorials on Youtube";
      this.linkLabel2.AutoSize = true;
      this.linkLabel2.Location = new Point(30, 151);
      this.linkLabel2.Name = "linkLabel2";
      this.linkLabel2.Size = new Size(242, 13);
      this.linkLabel2.TabIndex = 6;
      this.linkLabel2.TabStop = true;
      this.linkLabel2.Text = "http://www.youtube.com/user/TheDarkJoker094";
      // ISSUE: method pointer
      this.linkLabel2.LinkClicked += new LinkLabelLinkClickedEventHandler((object) this, __methodptr(linkLabel2_LinkClicked));
      this.label3.AutoSize = true;
      this.label3.Location = new Point(10, 171);
      this.label3.Name = "label3";
      this.label3.Size = new Size(91, 13);
      this.label3.TabIndex = 7;
      this.label3.Text = "More Software on";
      this.timer1.Interval = 500;
      // ISSUE: method pointer
      this.timer1.Tick += new EventHandler((object) this, __methodptr(timer1_Tick));
      this.label4.AutoSize = true;
      this.label4.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
      this.label4.Location = new Point(13, 73);
      this.label4.Name = "label4";
      this.label4.Size = new Size(88, 16);
      this.label4.TabIndex = 8;
      this.label4.Text = "Timer Interval:";
      this.textBox2.Location = new Point(102, 72);
      this.textBox2.Name = "textBox2";
      this.textBox2.Size = new Size(89, 20);
      this.textBox2.TabIndex = 9;
      this.textBox2.Text = "100";
      this.label5.AutoSize = true;
      this.label5.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
      this.label5.Location = new Point(197, 73);
      this.label5.Name = "label5";
      this.label5.Size = new Size(77, 16);
      this.label5.TabIndex = 10;
      this.label5.Text = "miliseconds";
      this.checkBox1.AutoSize = true;
      this.checkBox1.Checked = true;
      this.checkBox1.CheckState = CheckState.Checked;
      this.checkBox1.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
      this.checkBox1.Location = new Point(13, 103);
      this.checkBox1.Name = "checkBox1";
      this.checkBox1.Size = new Size(151, 20);
      this.checkBox1.TabIndex = 12;
      this.checkBox1.Text = "Send the ENTER key";
      this.checkBox1.UseVisualStyleBackColor = true;
      this.AutoScaleDimensions = new SizeF(6f, 13f);
      this.AutoScaleMode = AutoScaleMode.Font;
      this.ClientSize = new Size(284, 239);
      this.Controls.Add((Control) this.checkBox1);
      this.Controls.Add((Control) this.label5);
      this.Controls.Add((Control) this.textBox2);
      this.Controls.Add((Control) this.label4);
      this.Controls.Add((Control) this.label3);
      this.Controls.Add((Control) this.linkLabel2);
      this.Controls.Add((Control) this.label2);
      this.Controls.Add((Control) this.linkLabel1);
      this.Controls.Add((Control) this.label1);
      this.Controls.Add((Control) this.button2);
      this.Controls.Add((Control) this.button1);
      this.Controls.Add((Control) this.textBox1);
      this.FormBorderStyle = FormBorderStyle.FixedSingle;
      this.MaximizeBox = false;
      this.Name = "Form1";
      this.ShowIcon = false;
      this.Text = "SimpleSpammer";
      this.ResumeLayout(false);
      this.PerformLayout();
    }

    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
      Process.Start("http://thedarkjoker94.cer33.com/");
    }

    private void button1_Click(object sender, EventArgs e)
    {
      try
      {
        this.timer1.Interval = Convert.ToInt32(this.textBox2.Text);
        this.timer1.Start();
      }
      catch (Exception ex)
      {
        int num = (int) MessageBox.Show("An Exception was thrown!\n" + ex.Message, "ExceptionThrown");
      }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
      if (this.Focused)
        return;
      SendKeys.Send(this.textBox1.Text);
      if (this.checkBox1.CheckState == CheckState.Checked)
        SendKeys.Send("{ENTER}");
    }

    private void button2_Click(object sender, EventArgs e)
    {
      this.timer1.Stop();
    }

    private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
      Process.Start("http://www.youtube.com/user/TheDarkJoker094");
    }
  }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Spammer
{
    public partial class Form1 : Form
    {
        int delay, y = 1;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            delay = int.Parse(textBox2.Text);
            timer1.Interval = delay;
            timer1.Start();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Stop();
        }
        private void send()
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Focused)
            {
                return;
            }
            SendKeys.Send(textBox1.Text);
        }
    }
}
现在,您可以看到他的代码包含一个延迟字段、一个文本字段和“开始”/“停止”按钮

所以我试着做一些类似的事情,下面是代码:

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

namespace SimpleSpammer
{
  public class Form1 : Form
  {
    private IContainer components;
    private TextBox textBox1;
    private Button button1;
    private Button button2;
    private Label label1;
    private LinkLabel linkLabel1;
    private Label label2;
    private LinkLabel linkLabel2;
    private Label label3;
    private Timer timer1;
    private Label label4;
    private TextBox textBox2;
    private Label label5;
    private CheckBox checkBox1;

    public Form1()
    {
      this.components = (IContainer) null;
      base.\u002Ector();
      this.InitializeComponent();
    }

    protected override void Dispose(bool disposing)
    {
      if (disposing && this.components != null)
        this.components.Dispose();
      base.Dispose(disposing);
    }

    private void InitializeComponent()
    {
      this.components = (IContainer) new Container();
      this.textBox1 = new TextBox();
      this.button1 = new Button();
      this.button2 = new Button();
      this.label1 = new Label();
      this.linkLabel1 = new LinkLabel();
      this.label2 = new Label();
      this.linkLabel2 = new LinkLabel();
      this.label3 = new Label();
      this.timer1 = new Timer(this.components);
      this.label4 = new Label();
      this.textBox2 = new TextBox();
      this.label5 = new Label();
      this.checkBox1 = new CheckBox();
      this.SuspendLayout();
      this.textBox1.Location = new Point(13, 13);
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new Size(259, 20);
      this.textBox1.TabIndex = 0;
      this.textBox1.Text = "SPAM !";
      this.textBox1.TextAlign = HorizontalAlignment.Center;
      this.button1.Location = new Point(13, 39);
      this.button1.Name = "button1";
      this.button1.Size = new Size(75, 23);
      this.button1.TabIndex = 1;
      this.button1.Text = "Start";
      this.button1.UseVisualStyleBackColor = true;
      // ISSUE: method pointer
      this.button1.Click += new EventHandler((object) this, __methodptr(button1_Click));
      this.button2.Location = new Point(197, 39);
      this.button2.Name = "button2";
      this.button2.Size = new Size(75, 23);
      this.button2.TabIndex = 2;
      this.button2.Text = "Stop";
      this.button2.UseVisualStyleBackColor = true;
      // ISSUE: method pointer
      this.button2.Click += new EventHandler((object) this, __methodptr(button2_Click));
      this.label1.AutoSize = true;
      this.label1.Font = new Font("Arial", 8.25f, FontStyle.Italic, GraphicsUnit.Point, (byte) 0);
      this.label1.ForeColor = SystemColors.WindowFrame;
      this.label1.Location = new Point(7, 216);
      this.label1.Name = "label1";
      this.label1.Size = new Size(275, 14);
      this.label1.TabIndex = 3;
      this.label1.Text = "Copyright © 2010 TheDarkJoker94. This is a freeware.";
      this.linkLabel1.AutoSize = true;
      this.linkLabel1.Location = new Point(30, 190);
      this.linkLabel1.Name = "linkLabel1";
      this.linkLabel1.Size = new Size(162, 13);
      this.linkLabel1.TabIndex = 4;
      this.linkLabel1.TabStop = true;
      this.linkLabel1.Text = "http://thedarkjoker94.cer33.com";
      // ISSUE: method pointer
      this.linkLabel1.LinkClicked += new LinkLabelLinkClickedEventHandler((object) this, __methodptr(linkLabel1_LinkClicked));
      this.label2.AutoSize = true;
      this.label2.Location = new Point(10, 135);
      this.label2.Name = "label2";
      this.label2.Size = new Size(172, 13);
      this.label2.TabIndex = 5;
      this.label2.Text = "Check my C# Tutorials on Youtube";
      this.linkLabel2.AutoSize = true;
      this.linkLabel2.Location = new Point(30, 151);
      this.linkLabel2.Name = "linkLabel2";
      this.linkLabel2.Size = new Size(242, 13);
      this.linkLabel2.TabIndex = 6;
      this.linkLabel2.TabStop = true;
      this.linkLabel2.Text = "http://www.youtube.com/user/TheDarkJoker094";
      // ISSUE: method pointer
      this.linkLabel2.LinkClicked += new LinkLabelLinkClickedEventHandler((object) this, __methodptr(linkLabel2_LinkClicked));
      this.label3.AutoSize = true;
      this.label3.Location = new Point(10, 171);
      this.label3.Name = "label3";
      this.label3.Size = new Size(91, 13);
      this.label3.TabIndex = 7;
      this.label3.Text = "More Software on";
      this.timer1.Interval = 500;
      // ISSUE: method pointer
      this.timer1.Tick += new EventHandler((object) this, __methodptr(timer1_Tick));
      this.label4.AutoSize = true;
      this.label4.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
      this.label4.Location = new Point(13, 73);
      this.label4.Name = "label4";
      this.label4.Size = new Size(88, 16);
      this.label4.TabIndex = 8;
      this.label4.Text = "Timer Interval:";
      this.textBox2.Location = new Point(102, 72);
      this.textBox2.Name = "textBox2";
      this.textBox2.Size = new Size(89, 20);
      this.textBox2.TabIndex = 9;
      this.textBox2.Text = "100";
      this.label5.AutoSize = true;
      this.label5.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
      this.label5.Location = new Point(197, 73);
      this.label5.Name = "label5";
      this.label5.Size = new Size(77, 16);
      this.label5.TabIndex = 10;
      this.label5.Text = "miliseconds";
      this.checkBox1.AutoSize = true;
      this.checkBox1.Checked = true;
      this.checkBox1.CheckState = CheckState.Checked;
      this.checkBox1.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
      this.checkBox1.Location = new Point(13, 103);
      this.checkBox1.Name = "checkBox1";
      this.checkBox1.Size = new Size(151, 20);
      this.checkBox1.TabIndex = 12;
      this.checkBox1.Text = "Send the ENTER key";
      this.checkBox1.UseVisualStyleBackColor = true;
      this.AutoScaleDimensions = new SizeF(6f, 13f);
      this.AutoScaleMode = AutoScaleMode.Font;
      this.ClientSize = new Size(284, 239);
      this.Controls.Add((Control) this.checkBox1);
      this.Controls.Add((Control) this.label5);
      this.Controls.Add((Control) this.textBox2);
      this.Controls.Add((Control) this.label4);
      this.Controls.Add((Control) this.label3);
      this.Controls.Add((Control) this.linkLabel2);
      this.Controls.Add((Control) this.label2);
      this.Controls.Add((Control) this.linkLabel1);
      this.Controls.Add((Control) this.label1);
      this.Controls.Add((Control) this.button2);
      this.Controls.Add((Control) this.button1);
      this.Controls.Add((Control) this.textBox1);
      this.FormBorderStyle = FormBorderStyle.FixedSingle;
      this.MaximizeBox = false;
      this.Name = "Form1";
      this.ShowIcon = false;
      this.Text = "SimpleSpammer";
      this.ResumeLayout(false);
      this.PerformLayout();
    }

    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
      Process.Start("http://thedarkjoker94.cer33.com/");
    }

    private void button1_Click(object sender, EventArgs e)
    {
      try
      {
        this.timer1.Interval = Convert.ToInt32(this.textBox2.Text);
        this.timer1.Start();
      }
      catch (Exception ex)
      {
        int num = (int) MessageBox.Show("An Exception was thrown!\n" + ex.Message, "ExceptionThrown");
      }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
      if (this.Focused)
        return;
      SendKeys.Send(this.textBox1.Text);
      if (this.checkBox1.CheckState == CheckState.Checked)
        SendKeys.Send("{ENTER}");
    }

    private void button2_Click(object sender, EventArgs e)
    {
      this.timer1.Stop();
    }

    private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
      Process.Start("http://www.youtube.com/user/TheDarkJoker094");
    }
  }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Spammer
{
    public partial class Form1 : Form
    {
        int delay, y = 1;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            delay = int.Parse(textBox2.Text);
            timer1.Interval = delay;
            timer1.Start();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Stop();
        }
        private void send()
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Focused)
            {
                return;
            }
            SendKeys.Send(textBox1.Text);
        }
    }
}
我昨天发布了一个类似的问题,但这个问题要准确得多

在他的程序中,我输入了一些文本,选择了10毫秒的延迟并启动了它。发送几秒钟后,我点击了他的程序中的“停止”按钮,它立即停止发送按键

现在。。。当我运行程序并开始发送按键(延迟10毫秒)时,我让它运行几秒钟,然后按下“停止”。什么也没发生,“停止”甚至没有点击。它只是在周围显示了一个蓝色的框架,我无法点击它

当然,正因为如此,它并没有停止发送密钥


那么,为什么它在他的程序中运行得很好,但在我的程序中却根本不起作用呢?

我的第一个想法是10毫秒太快了,而且计时器一直在运行,没有给消息循环的其余部分一个响应的机会。如果使用100毫秒延迟而不是10毫秒延迟,问题是否仍然存在?不知道为什么你的程序和他的不同…也许它速度很快,但事实是它在他的程序上运行得非常完美。我也尝试过Form1.Focused,但它说需要对象引用。。。