C# 密钥访问另一个应用程序

发布于 2024-11-25 05:34:31 字数 94 浏览 3 评论 0原文

我想将击键发送到另一个应用程序。例如:我打开了浏览器,我想将击键写入打开的记事本应用程序,而不定位记事本窗口。我只想让浏览器窗口始终处于活动状态。

是否可以?

I want to send keystrokes to another application. For example: I have opened a browser and I want write keystrokes to an opened notepad app without targeting notepad window. I just want for the browser window to be active the whole time.

Is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别低头,皇冠会掉 2024-12-02 05:34:31

如果您确实想将击键从网络浏览器发送到正在运行的Windows应用程序,那么这不应该是可能的。

原因是网络浏览器是(或应该)与操作系统和其他正在运行的应用程序隔离的沙箱,以防止不良分子通过互联网恶意干扰您的计算机。

If you really do mean sending keystrokes from a web browser to a running Windows application then this shouldn't be possible.

The reason is that web browsers are (or should be) sandboxed from the OS and other running applications to prevent undesirables from maliciously interfering with your computer via the internet.

倾其所爱 2024-12-02 05:34:31

如果您使用 Windows API,则可以,但是 SendInput 是唯一能保证正确执行此操作的 API,并且仅在聚焦窗口上执行此操作。对于其他窗口,您可以使用 SendMessageWM_KEYUPWM_KEYDOWNWM_CHAR,但它非常不可靠。对于应用程序来说,这样做通常也是不受欢迎的行为。

You can, if you use the Windows API, however SendInput is the only one that will be guaranteed to do it properly, and only does so on the focused window. For other windows, you can use SendMessage, with WM_KEYUP, WM_KEYDOWN and WM_CHAR, but it's pretty unreliable. It's also usually undesirable behavior for an application to do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文