我怎么能模拟从code小鼠的事件? [英] How can I simulate mouse events from code?

查看:122
本文介绍了我怎么能模拟从code小鼠的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模拟使用Win32 API的鼠标事件;我该怎么办呢?

I would like to simulate mouse events using the Win32 API; how can I do it?

我想要做的是在最基本的级别模拟的情况下,在该系统具有只事件类型和坐标,尚未想通哪个窗口它必须将其传输到的水平。

What I want to do is simulate the event at the most basic level, the level at which the system has just the event type and the co-ordinates and hasn't yet figured which window it must relay it to.

我不知道这是否是如何工作的。无论哪种方式,我需要帮助这样做。我会在驱动程序级别染指?!

I don't know if that's how things work. Either way, I need help doing it. Would I have to meddle at the driver level?!

为了使我的要求清楚,我不想针对任何窗口,我只想系统认为鼠标被点击或由用户移动。我将编码以下。

To make my requirements clear, I don't want to target any window, I just want the system to think the mouse was clicked or moved by the user. And I would be coding in C.

推荐答案

您正在寻找的 < STRONG> SendInput 功能,它可以让你的鼠标合成
移动和按钮点击在code通过指定 输入数组结构

You're looking for the SendInput function, which allows you to synthesize mouse movements and button clicks in your code by specifying an array of INPUT structures corresponding to input events.

UINT WINAPI SendInput(
  __in  UINT nInputs,     // number of structures in the pInputs array
  __in  LPINPUT pInputs,  // an array of INPUT structures, representing an event
  __in  int cbSize        // the size, in bytes, of an INPUT structure
);

请注意,但是,此功能受到用户界面特权隔离(UIPI),这意味着你的应用程序只允许注入输入到被以相等或更低的完整性级别运行的应用程序。

Note, however, that this function is subject to User Interface Privilege Isolation (UIPI), which means that your application is only permitted to inject input to applications that are running at an equal or lesser integrity level.

这篇关于我怎么能模拟从code小鼠的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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