如何在Delphi中使用SendInput? [英] How Do I Use SendInput in Delphi?

查看:333
本文介绍了如何在Delphi中使用SendInput?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Delphi 2009中使用了Mouse_Event函数,但是Delphi文档说该函数已被取代,而改用SendInput.

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.

Delphi SendInput文档定义了语法和参数,但是没有示例,并且不清楚如何使用该函数.我在网上四处张望,找不到任何好的Delphi示例.

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.

具体来说,我正在尝试模拟鼠标左键然后再向上键.目前,我使用Mouse_Event进行以下操作:

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

我该如何使用SendInput做到这一点?

How would I do this using SendInput?

跟进:

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

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

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

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.

推荐答案

此处是模拟左键单击以了解更多详细信息的方法,请访问

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;

这里是模拟右键单击

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;

这篇关于如何在Delphi中使用SendInput?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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