开发者

SendKeys::Send, going berserk

开发者 https://www.devze.com 2023-04-12 15:07 出处:网络
I am trying to make updates to two linked TextBoxes. I disable events in one and then send keystrokes using eg SendKeys::Send(\"A\"); having first given it focus:

I am trying to make updates to two linked TextBoxes. I disable events in one and then send keystrokes using eg SendKeys::Send("A"); having first given it focus:

texBox2->Focus();
texBox2->KeyDown -= gcnew KeyEventHandler(this, &Form1::texBox2_KeyDown);
SendKeys::Send("A");
texBox2->KeyDown += gcnew KeyEventHandler(this, &Form1::texBox2_KeyDown);

It almost works but goes totally mental instead repeating the character (I daren't look to check which exact key because I'm frantically firefighting an overflow) until I press control-alt-del. No other keys have any effect and the mouse freezes up. But task man开发者_如何学编程ager miraculously restores my control, I don't stop or kill anything from it.

Can anyone advise? The debugger hangs on that SendKeys::Send("A"); statement.


SendKeys places input in the message queue which is queued and so will get processed after you have reconnected the events. Hence the wackiness.

My advice is to stop using SendKeys to update the contents of your own controls. Simply modify the contents of the text boxes directly.

0

精彩评论

暂无评论...
验证码 换一张
取 消