John
John

Reputation: 6648

SendKeys::Send, going berserk

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 manager 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.

Upvotes: 1

Views: 901

Answers (1)

David Heffernan
David Heffernan

Reputation: 613053

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.

Upvotes: 5

Related Questions