2009-11-23 57 views
0

即时通讯尝试做一个自动化工具,用于在工作中为调度程序应用程序提供带有用户名的文本框。键盘模拟新闻事件的问题

林有一些问题试图simultate键按压,如果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; 
     } 
    } 

回答

2

你永远不会从你的KeyboardSimulator发射KeyUp命令。当钥匙掉下来时,不能再次按下。您必须让KeyUp才能启动新的KeyDown事件。

+0

啊OFC,感谢队友指出了这一点。 – Darkmage 2009-11-23 17:38:14

+0

杰夫你因为我第一次得到了我的+1。不知道为什么我的回答被接受了,但我觉得这和我一样好。 – 2009-11-23 17:45:47

+0

谢谢 - 但我确实认为你的回答更清楚一点,因为他只有一个电话让你和两个人用我的解决方案做出决定。无论哪种方式,猫都被剥皮,一天就完成了。所以,+1我回到你身边。 – Jeff 2009-11-23 17:51:50

2

尝试changing KeyboardSimulator.KeyDown(keys); 使用KeyboardSimulator.KeyPress(keys);

我不知道,如果在KeyDown事件将检查键的状态,如果它已经下来..

+0

非常好,就是我之后。我怎么不这样做。 – Darkmage 2009-11-23 17:40:57