我可以强制“按下”退出键吗?在 C++ 中?
我知道,如果用户按下设置键(在我的例子中是 Escape),您可以设置要触发的操作,如下所示:
transitions.push_back(new KeyTransition("GameMode", OIS::KC_ESCAPE));
我想知道的是,是否可以让程序“认为”Escape 键已被按下,即使如果没有。例如,当用户单击按钮时,程序会模拟退出键已被按下并触发附加的事件。
I know that you can set actions to trigger if the user presses a set key, in my case Escape, with something like this:
transitions.push_back(new KeyTransition("GameMode", OIS::KC_ESCAPE));
What I want to know is if I can have the program "think" the Escape key has been pressed, even if it has not. For example, when the user clicks a button, the program simulates that the escape key has been pressed and triggers the event attached to it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实现此目的的一种方法是将其绑定到特定的按键事件,您可以使用更通用的方法。
因此,无论 ESC 正在做什么,都有像
Cancel()
或GoBackOneScreen()
等方法。然后,您可以让 ESC 按键调用GoBackOneScreen()
,当您需要模拟 ESC 按键时,只需调用GoBackOneScreen()
方法即可。One way to do this would be instead of tying it to a specific key press event, you had a more generic method.
So have a method like
Cancel()
orGoBackOneScreen()
etc, whatever it is that ESC is doing. Then you could have the ESC keypress callGoBackOneScreen()
and when you needed to simulate the ESC key press, you could do it by just calling theGoBackOneScreen()
method.请参阅:如何在不使用 Windows API 激活窗口的情况下将击键发送到窗口?
摘要:你不能可靠地做到这一点。
See this: How do I send key strokes to a window without having to activate it using Windows API?
Summary: You can't reliably.