c# - 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();
}
}
}
解决方案
推荐阅读
- sftp - Azure 逻辑应用 SFTP-SSH 创建操作中的分块不起作用
- mongodb - Spring Boot mongo db连接池问题
- git - 仅克隆一个 gitlab 存储库时出错
- python - 如何将屏幕导入主屏幕?基维
- php - Ajax POST,检查 PHP $_GET 然后 $_POST
- r - sf:生成具有最大距离条件的随机点
- javascript - 在反应本机挂钩中更新嵌套数据状态
- python - ValueError: y 应该是一维数组,得到一个形状为 (9121, 14) 的数组
- flutter - 如何浏览已经打开的页面 [Flutter]?
- javascript - 如何配置 laravel-websockets 包以使用从子目录提供的 Laravel 应用程序,即 https://laravel-apps.test/app1?