如何在 Delphi 中使用 SendInput?

发布于 2024-11-18 09:09:09 字数 601 浏览 3 评论 0原文

我在 Delphi 2009 中使用 Mouse_Event 函数,但 Delphi 文档说该函数已被取代并使用 SendInput 代替。

Delphi SendInput 文档定义了语法和参数,但没有示例,也不清楚如何使用该函数。我在网上查了一下,没有找到任何好的 Delphi 示例。

具体来说,我试图模拟鼠标左键向下然后向上。目前,我使用 Mouse_Event 执行此操作,如下所示:

    Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

我将如何使用 SendInput 执行此操作?


后续:

我最终按照@David的建议保留了我的代码。

但我给了@opc0de 答案,因为他确实回答了我的问题。但是,我不能保证它是正确的,因为我从未尝试过。

I was using the Mouse_Event Function in Delphi 2009, but the Delphi documentation says this function has been superceded and to use SendInput instead.

The Delphi SendInput documentation defines the syntax and parameters, but there are no examples and it is not clear how to use the function. I've looked around on the web, and can't find any good Delphi examples.

Specifically, I am trying to simulate the left mouse down and then up. Currently I do this with Mouse_Event as follows:

    Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

How would I do this using SendInput?


Followup:

I ended up leaving my code as is as @David suggested.

But I gave @opc0de the answer since he did give an answer to my question. However, I can't vouch that it is correct, because I never did try it.

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

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

发布评论

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

评论(1

昔日梦未散 2024-11-25 09:09:09

以下是如何模拟左键单击,有关更多详细信息,请访问 http://msdn.microsoft .com/en-us/library/ms646310(VS.85).aspx

var
eu: array [0..1] of TInput;
begin
  ZeroMemory(@eu,sizeof(eu));
  eu[0].Itype := INPUT_MOUSE;
  eu[0].mi.dwFlags :=MOUSEEVENTF_LEFTDOWN;
  eu[1].Itype := INPUT_MOUSE;
  eu[1].mi.dwFlags :=MOUSEEVENTF_LEFTUP;
  SendInput(2,eu[0],sizeof(TInput));
end;

这里用于模拟右键单击

var
eu: array [0..1] of TInput;
begin
  ZeroMemory(@eu,sizeof(eu));
  eu[0].Itype := INPUT_MOUSE;
  eu[0].mi.dwFlags :=MOUSEEVENTF_RIGHTDOWN;
  eu[1].Itype := INPUT_MOUSE;
  eu[1].mi.dwFlags :=MOUSEEVENTF_RIGHTUP;
  SendInput(2,eu[0],sizeof(TInput));
end;

Here is how to simulate a left click for more details visit http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx

var
eu: array [0..1] of TInput;
begin
  ZeroMemory(@eu,sizeof(eu));
  eu[0].Itype := INPUT_MOUSE;
  eu[0].mi.dwFlags :=MOUSEEVENTF_LEFTDOWN;
  eu[1].Itype := INPUT_MOUSE;
  eu[1].mi.dwFlags :=MOUSEEVENTF_LEFTUP;
  SendInput(2,eu[0],sizeof(TInput));
end;

And here is for simulating right click

var
eu: array [0..1] of TInput;
begin
  ZeroMemory(@eu,sizeof(eu));
  eu[0].Itype := INPUT_MOUSE;
  eu[0].mi.dwFlags :=MOUSEEVENTF_RIGHTDOWN;
  eu[1].Itype := INPUT_MOUSE;
  eu[1].mi.dwFlags :=MOUSEEVENTF_RIGHTUP;
  SendInput(2,eu[0],sizeof(TInput));
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文