SendKeys::Send, going berserk

天大地大妈咪最大 提交于 2019-12-24 17:25:36

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7718220/sendkeyssend-going-berserk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!