【发布时间】:2009-11-23 17:29:04
【问题描述】:
我正在尝试制作一个自动化工具,用于在工作中为调度程序应用程序填充用户名的文本框。
如果 inputArrayX[i] 数组包含 a,b,c,我在尝试模拟按键时遇到了一些问题
keyboardsim 会按 abc,但如果数组包含 a、b、b、c、c,它仍然只输入 abc,而不是像我想要的那样输入 abbcc。
有人知道我在这里做错了什么吗?
private void MouseMacroChangeUser()
{
//move form to 0,0
this.Location = new Point(0, 0);
//set xy to mouse current pos
userMousePos();
//inputBlocker();
xX = int.Parse(this.Location.X.ToString());
yY = int.Parse(this.Location.Y.ToString());
defaultMousePos();
//Thread.Sleep(600);
Cursor.Position = new Point(Cursor.Position.X + 739, Cursor.Position.Y + 162);
//Thread.Sleep(100);
MouseSimulator.DoubleClick(MouseButton.Left);
for (int i = 0; i < inputArrayX.Length; i++)
{
string tempX = inputArrayX[i].ToString();
Keys keys = mapToKeyboardMacro(tempX);
KeyboardSimulator.KeyDown(keys);
}
KeyboardSimulator.KeyPress(Keys.Enter);
MouseSimulator.Click(MouseButton.Left);
//reset mouse to user pos.
Cursor.Position = new Point(x, y);
needUnblock = true;
//inputBlocker();
}
private Keys mapToKeyboardMacro(string key)
{
if (key == "space")
{
return Keys.Space;
}
else if (key == "a")
{
return Keys.A;
}
else if (key == "b")
{
return Keys.B;
}
else if (key == "c")
{
return Keys.C;
}
else if (key == "d")
{
return Keys.D;
}
}
【问题讨论】: