SendKeys.Send 并关闭按键修饰符
我想让 ^N 与树控件中的向下箭头一样工作。 我想 我只需将以下内容添加到 KeyDown 处理程序中:
SendKeys.Send("{Down}");
但这会被视为 Control-Down 箭头,因为 control 键 当前被按下。 msdn 页面 描述了如何打开 控制修饰符,但不知道如何关闭它。
谢谢, 基思
I want to make ^N work the same as Down arrow in a tree control. I thought
I'd just have to add the following to the KeyDown handler:
SendKeys.Send("{Down}");
but this gets treated as a Control-Down arrow since the control key
is currently pressed. The msdn page
describes how to turn on the
control modifier but not how to turn it off.
Thanks,
Keith
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
抱歉来晚了,但我想我找到了一个解决方案:
首先,导入 SetKeyboardState:
然后,在调用 SendKeys.Send() 之前用归零的字节数组调用它:
这对我有用。 希望这可以帮助!
Sorry to come late to the party but I think I found a solution:
First, import SetKeyboardState:
Then, just call it with a zeroed byte array before calling SendKeys.Send():
That worked for me. Hope this helps!
您可以 p/调用 keybd_event。 这将让您模拟处于“向上”和“向下”状态的按键。
You can p/invoke to keybd_event. That will let you simulate a key being both in "up" and "down" state.
这是做到这一点的困难方法。 我承认这不是最佳方法。 我相信你已经知道这一点了。 您可能想要重载控件的 WindProc 方法。 使用 SendMsg Win32 Api。 这就是我过去如何让事情恢复正常的。
Here's the hard way of doing it. I admit this is not the optimal way to do it. I'm sure you already know this. You might want to overload the WindProc method of the control & use SendMsg Win32 Api. This is how I used get things to work back in the day.
您也可以尝试等到不再按下控制键时才
KeySend
,例如:You can also try to wait until the control key is no longer pressed and only then
KeySend
, e.g.: