我编写了一个循环,当我按住空格键时,该空格会向空格键(低级输入)发送垃圾邮件。确实可以,但是当我按住空格键的同时按任何其他键时,它突然停止工作。我该如何解决?我正在使用here中的InputManager API。
private void GlobalHookKBKeyUp(object sender, KeyEventArgs e)
{
if (spacePressed == true)
{
if (e.KeyCode == Keys.Space)
{
spacePressed = false;
timer1.Stop();
}
}
}
private void GlobalHookKBKeyDown(object sender, KeyEventArgs e)
{
if (checkBox2.Checked == true)
{
if (canJump == true)
{
if (e.KeyCode == Keys.Space)
{
spacePressed = true;
timer2.Start();
}
}
}
}
private void timer2_Tick(object sender, EventArgs e)
{
if (spacePressed == true)
{
Keyboard.KeyPress(Keys.Space);
}
}