如何在 c++ 中将快捷方式发送到另一个应用程序在微软视窗中?
我的问题是如何将快捷方式从 C++ 发送到另一个应用程序。比方说,记事本已打开,我想向他们发送快捷键(如 CTRL+P),或更复杂的快捷键(如 CTRL+SHIFT+HOME 或 ALT+F4),我发现许多很好的教程解释了如何发送一键像“A”或“ALT”,但我没有找到如何将它们一起发送。
My question is how to send shortcut from c++ to another application. Let's say for example that the notepad is open, and I want send to them shortcut like CTRL+P, or more complexive shortcut like CTRL+SHIFT+HOME, or ALT+F4, I find many good tutorials that explained how to send one key like 'A' or 'ALT', but I did not find how to send it together.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
SendInput()
或keybd_event()
将按键发送到当前聚焦的窗口。SendInput()
可能是更好的选择,因为它不会将键盘事件与实际键盘的事件分散。You can use
SendInput()
orkeybd_event()
to send keys to the currently focused window.SendInput()
might be the better choice as it would not intersperse the keyboard events with those form the actual keyboard.您可以发送多个 WM_KEYDOWN,然后发送多个 WM_KEYUP,这样您就可以尝试发送 DOWN ctrl、shift、home、UP home、shift、ctrl - 这应该可以解决问题。
You can send a number of WM_KEYDOWNs followed by a number of WM_KEYUPs so you could try sending DOWN ctrl, shift, home, UP home, shift, ctrl - that should do the trick.
这种“组合键”在 Microsoft Windows 中通常称为键盘加速器。 MSDN 介绍页面
This kind of "key combinations" is usually called Keyborad Accelerators in Microsoft Windows. The MSDN intro page