SendKeys :: Send, going berserk

I am trying to make updates for two related TextBox es. I will disable events in one, and then send keystrokes using, for example, SendKeys::Send("A"); by first specifying the 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 it goes completely mentally, instead repeating the character (I don’t see to check which key, because I feverishly burned out the overflow) until I press the control-alt-del button. No other keys work and the mouse freezes. But the task manager miraculously regains my control, I stop nothing and do not kill.

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

+1
source share
1 answer

SendKeys places the input in the message queue, which is queued, and therefore will be processed after the events are reconnected. Hence the stupidity.

My advice: stop using SendKeys to update the contents of your own controls. Just change the contents of the text fields directly.

+5
source

Source: https://habr.com/ru/post/1380776/


All Articles