模拟鼠标移动/单击/键在不活动的应用程序中按 [英] Simulate Mouse move/click/keyPress in an application that is not active

查看:62
本文介绍了模拟鼠标移动/单击/键在不活动的应用程序中按的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何模拟鼠标和键盘事件,但是它们的行为就像用户执行它们一样,因此它们将影响活动的窗口.我需要模拟这些输入之一,但是要在不活动的窗口中进行模拟.

I know how to simulate mouse and keyboard events, but they act as if the user did them, so they will affect the window that is active. What I need is to simulate one of those inputs, but in a Window that is not active.

我并不是说它已被最小化,例如,假设您有msPaint和记事本.记事本在油漆前面.而且,您想在绘制窗口的某些坐标上模拟鼠标单击,但是没有将其设置为活动状态,因此用户可以继续使用位于绘制区域的记事本.

I'm not saying that it is minimized, imagine for example, you have msPaint, and notepad. Notepad is in front of paint. And you want to simulate mouse clicks in certain coordinates of the paint window, but without setting it active, making it possible for the user to keep using notepad which is in fron of paint.

这有可能吗? 谢谢!

推荐答案

您可以执行以下操作:

1)获取要在其中模拟事件的窗口的HWND.为此,可以使用FindWindow函数,该函数具有两个参数,一个是窗口的类名(可以使用NULL),另一个是窗口的名称(有关详细信息,请参见MSDN文档);

1) get the HWND of the window inside which you want to simulate events. In order to do this you can use the FindWindow function, which takes two parameters, one being the window's class name (you can use NULL) and the other the name of the window (see MSDN documentation for details);

2)使用SendMessage功能将消息发送到所需的窗口.参数为:先前获得的窗口句柄(HWND),消息(例如,可以为WM_KEYDOWNWM_MOUSEMOVEWM_LBUTTONDOWN等),消息的WPARAM(以防万一) WM_KEYDOWN是密钥的虚拟密钥代码),最后是消息的LPARAM(在WM_KEYDOWN的情况下,它非常复杂,您应该检查MSDN以获得详细信息.)

2) send a message to the desired window using SendMessage function. The parameters are: the previous obtained window handle (HWND), the message (which can be for example WM_KEYDOWN, or WM_MOUSEMOVE, WM_LBUTTONDOWN etc.), the WPARAM of the message (which in case of WM_KEYDOWN is the virtual key code of the key) and finally the LPARAM of the message (which in case of WM_KEYDOWN is quite complex and you should check MSDN for details).

我认为这足以满足您的计划.

In my opinion this is sufficient for what you intend to do.

这篇关于模拟鼠标移动/单击/键在不活动的应用程序中按的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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