首页 > 解决方案 > Visual Studio C# 为游戏发送输入

问题描述

我正在尝试做一个按下按钮的程序,就像我只是在我自己的键盘上按下它一样。它在 txt 文件或其他地方完美运行,但在游戏中却不行。游戏是metin2。

谢谢!

public partial class Form1 : Form
{
    int spaceCount = 0;
    bool startPressed = false;

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (!startPressed)
        {
            startPressed = true;
            Timer timer = new Timer();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 1000;
            timer.Enabled = true;
            timer.Start();
        }
    }

    void timer_Tick(object sender, EventArgs e)
    {
        InputSimulator IS;
        IS = new InputSimulator();
        IS.Keyboard.KeyPress(VirtualKeyCode.SPACE);
        Keyboard.KeyPress(Keys.Space);
        spaceCount++;
        label1.Text = spaceCount.ToString();
    }
}

}

标签: c#winforms

解决方案


推荐阅读