在 .net 中单击按钮切换到另一个应用程序(以前处于活动状态)
嗨,我想做一些类似屏幕键盘的事情。我希望用户单击非活动应用程序上的按钮,然后按键将被发送到活动应用程序,同时保持活动应用程序处于活动状态。我为非活动应用程序中按钮的悬停事件编写了代码,并且它正在工作。但我想要的是在点击事件中做到这一点。它不起作用,因为不活动的应用程序变为活动的。悬停事件的代码如下。谢谢。
private void button1_MouseHover(object sender, EventArgs e)
{
SendKeys.Send("{TAB}");
}
Hi I want to do something like on screen keyboard. I want user to click a button on inactive application and then key press will be sent to active application while keeping active application active. I wrote the code for hover event of the button in inactive application and it is working. But what I want is to do it in click event. It is not working because inactive application becomes active. The code is below for hover event. Thank you.
private void button1_MouseHover(object sender, EventArgs e)
{
SendKeys.Send("{TAB}");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后我能找到一种方法来做到这一点。
请参考下面的代码。
Finally I could figure out a way to do it.
Refer the code below.
我从未做过类似的事情,但这是我在 forum:
它并不能完全回答你的问题,但会给你一个提示。您需要DllImport“User32.dll”。之后你就可以获得前台窗口的 id 并使用它。
还有一篇非常有趣的关于应用程序切换跟踪的文章 C#
I have never done something similar, but here is what I found in this forum:
It doesn't answer exactly to your question but it will give you a hint. You need to DllImport "User32.dll". After that you can get the id of the foreground window and play with that.
There is also a very interesting article about application switch tracking written in C#