我认为标题解释了我的问题。
我需要
SendKeys
在DoMouseClick
方法之前完成发送密钥,否则我的整个程序就没用了。
// Simulate the keyboard typing the value of 'i'
SendKeys.SendWait(i.ToString());
// Simulate mouse click so the Accept button in-game is clicked
DoMouseClick();
我尝试使用
Thread.Sleep
,但我希望你们对如何解决我的问题有一些更好的建议。
使用输入模拟器。它比
SendKeys
好得多,并且可以在内部处理边缘情况。
Install-Package InputSimulator
var simulator = new InputSimulator();
//simulate what you need
simulator.Keyboard.KeyPress(VirtualKeyCode.VK_I);
simulator.Keyboard.TextEntry(i.ToString());
simulator.Mouse.LeftButtonDoubleClick();
我不确定这是否有帮助,但如果没有的话请批评这篇文章,以便我可以尽力帮助您解决问题。
private void Form1_DoubleClick(object sender, MouseEventArgs e)
{
// Send the enter key; since the tab stop of Button1 is 0, this
// will trigger the click event.
SendKeys.SendWait("{ENTER}");
CallAfterSend();
}
private void CallAfterSend()
{
MessageBox.Show("Had to hit enter first");
}
private void button1_Click_1(object sender, EventArgs e)
{
MessageBox.Show("Click here!");
}