在向 DirectX 应用程序发送击键之间暂停
Pause between sending keystrokes to DirectX Application
我想将一系列按键(组成一个词)发送到 DirectX 应用程序的 window,然后在发送 ENTER
键之前暂停。
我可以使用 InputManager 库发送单个按键,但我不确定如何使用此键盘挂钩在某些键序列之间实现 "waits"。
即:发送消息"Hello",等待250ms,然后是ENTER
键。
SendKeys 和 SendWait 对我正在做的事情不起作用,因为它们不会将击键发送到 DirectX 应用程序。
下面是一些伪代码,解释了我要完成的任务:
using InputManager;
namespace MyProject
{
public partial class form1: Form
{
private void helloButton_Click(object sender, EventArgs e)
{
Keyboard.KeyPress(Keys.H);
Keyboard.KeyPress(Keys.E);
Keyboard.KeyPress(Keys.L);
Keyboard.KeyPress(Keys.L);
Keyboard.KeyPress(Keys.O);
// (Wait 250ms)
Keyboard.KeyPress(Keys.Enter);
}
}
}
您可以使用 Thread.Sleep(250);
。这将使当前工作的线程暂停 x
毫秒数。
请注意,您需要在 using 语句中包含 System.Threading
。
我想将一系列按键(组成一个词)发送到 DirectX 应用程序的 window,然后在发送 ENTER
键之前暂停。
我可以使用 InputManager 库发送单个按键,但我不确定如何使用此键盘挂钩在某些键序列之间实现 "waits"。
即:发送消息"Hello",等待250ms,然后是ENTER
键。
SendKeys 和 SendWait 对我正在做的事情不起作用,因为它们不会将击键发送到 DirectX 应用程序。
下面是一些伪代码,解释了我要完成的任务:
using InputManager;
namespace MyProject
{
public partial class form1: Form
{
private void helloButton_Click(object sender, EventArgs e)
{
Keyboard.KeyPress(Keys.H);
Keyboard.KeyPress(Keys.E);
Keyboard.KeyPress(Keys.L);
Keyboard.KeyPress(Keys.L);
Keyboard.KeyPress(Keys.O);
// (Wait 250ms)
Keyboard.KeyPress(Keys.Enter);
}
}
}
您可以使用 Thread.Sleep(250);
。这将使当前工作的线程暂停 x
毫秒数。
请注意,您需要在 using 语句中包含 System.Threading
。