模拟鼠标移动/单击/按下非活动应用程序中的按钮

时间:2022-11-03 19:53:58

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.

我知道如何模拟鼠标和键盘事件,但它们就像用户那样做,因此它们会影响活动的窗口。我需要的是模拟其中一个输入,但在一个不活动的窗口中。

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.

我并不是说它被最小化了,想象一下,例如,你有msPaint和记事本。记事本在油漆面前。并且您希望在绘画窗口的某些坐标中模拟鼠标点击,但不将其设置为活动状态,从而使用户可以继续使用油漆边缘的记事本。

Is this possible at all? Thanks!

这有可能吗?谢谢!

2 个解决方案

#1


You might do the following:

您可以执行以下操作:

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);

1)获取要在其中模拟事件的窗口的HWND。为此,您可以使用FindWindow函数,它接受两个参数,一个是窗口的类名(可以使用NULL),另一个是窗口的名称(有关详细信息,请参阅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).

2)使用SendMessage函数向所需窗口发送消息。参数是:先前获得的窗口句柄(HWND),消息(可以是例如WM_KEYDOWN,或WM_MOUSEMOVE,WM_LBUTTONDOWN等),消息的WPARAM(在WM_KEYDOWN的情况下是密钥的虚拟密钥代码) )最后消息的LPARAM(在WM_KEYDOWN的情况下非常复杂,您应该检查MSDN的详细信息)。

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

在我看来,这足以满足你的目的。

#2


Well if you knew JAVA you could use the robots class.

好吧,如果你知道JAVA,你可以使用机器人课程。

This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed

此类用于生成本机系统输入事件,用于测试自动化,自运行演示以及需要控制鼠标和键盘的其他应用程序

Java robots class

Java机器人类

Maybe theres something simular in .net?

也许在.net中有类似的东西?

#1


You might do the following:

您可以执行以下操作:

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);

1)获取要在其中模拟事件的窗口的HWND。为此,您可以使用FindWindow函数,它接受两个参数,一个是窗口的类名(可以使用NULL),另一个是窗口的名称(有关详细信息,请参阅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).

2)使用SendMessage函数向所需窗口发送消息。参数是:先前获得的窗口句柄(HWND),消息(可以是例如WM_KEYDOWN,或WM_MOUSEMOVE,WM_LBUTTONDOWN等),消息的WPARAM(在WM_KEYDOWN的情况下是密钥的虚拟密钥代码) )最后消息的LPARAM(在WM_KEYDOWN的情况下非常复杂,您应该检查MSDN的详细信息)。

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

在我看来,这足以满足你的目的。

#2


Well if you knew JAVA you could use the robots class.

好吧,如果你知道JAVA,你可以使用机器人课程。

This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed

此类用于生成本机系统输入事件,用于测试自动化,自运行演示以及需要控制鼠标和键盘的其他应用程序

Java robots class

Java机器人类

Maybe theres something simular in .net?

也许在.net中有类似的东西?