SendInput到最小化窗口 [英] SendInput to minimized window

查看:234
本文介绍了SendInput到最小化窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在当前没有焦点的窗口上使用sendInput函数,并且可能通过使用多线程,同时将sendinput到多个最小化的窗口或在工作时将输入发送到一个窗口来实现

Is it possible to utilize the sendInput function on windows that currently do not have focus, and maybe through the use of multithreading, sendinput to multiple minimized windows at the same time, or send input to one window while you're working on another window?

我想在c#

预先做这样的事情。

推荐答案

您只能使用 SendInput 通过键盘焦点将输入发送到HWND 。此外,该窗口必须附加到调用线程的消息队列中,因此也不能简单地 SetFocus

You can only use SendInput to send input to the HWND with keyboard focus. Furthermore the window must be attached to the calling thread's message queue, so one cannot simply SetFocus either.

将需要使用 GetProcessIdOfThread

You'll need to get the window's thread id with GetProcessIdOfThread.

拥有线程ID时,可以使用 AttachThreadInput 函数将您的线程附加到其他线程输入处理。

When you have the thread id you can use the AttachThreadInput function to attach your thread to the other threads input processing.

毕竟,您可能可以使用 SetFocus SendInput

After all this you can probably use SetFocus and SendInput.

发送输入后,您可能希望分离线程。

You'll probably want to detach your thread when you've sent your input.

获取访问权限对于这些方法,您必须对C#或C ++ / CLI使用P / Invoke。 PInvoke.net 非常方便。导入所有这些功能将是一件小事,但是完成后,您应该能够将输入发送到所需的任何窗口。

To get access to these method you'll have to use P/Invoke for C# or C++/CLI. PInvoke.net is very handy as a reference. It will be a small chore importing all those functions, but when you are done you should be able to send input to whatever "window" you want.

另外,我不确定您是否意识到这一点,但是在纯Win32中,所有内容都被视为窗口,甚至是按钮。如果您不走运,则可能必须将输入发送到属于记事本应用程序的文本控件的句柄。

Also as a side note, I'm not sure if you are aware of this, but in pure Win32 everything is regarded as a window, even a button. If you are unlucky you may have to send the input to the handle of the text control belonging to the notepad application.

这篇关于SendInput到最小化窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆