模拟键盘输入疑难问题
彗星 2011-07-28 12:57:53 请教大家个问题:
我现在弹出个错误的对话框,有重试和取消按钮,我想模拟键盘输入连续按回车键三次,就是连续点“重试”按钮,我的一下代码可以做到弹出重试按钮对话框后模拟键盘回车一次,但是要模拟三次怎么做呢?代码如下:
private void txttransferno_KeyPress(object sender, KeyPressEventArgs e)
{
timer1.Enabled = true;
this.ShowErrDialog(output.ErrorMessage);
}
private void timer1_Tick(object sender, EventArgs e)
{
SendKey(0x0D);
timer1.Enabled = false;
}
private void SendKey(byte key)
{
const int KEYEVENTF_KEYUP = 0x02;
const int KEYEVENTF_KEYDOWN = 0x00;
keybd_event(key, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(key, 0, KEYEVENTF_KEYUP, 0);
}
private void ShowErrDialog(string msg)
{
if (MessageBox.Show(msg, this.Text, MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Retry)
{
ShowErrDialog(msg);
}
}