SendInput 函数怎么用

谁学逆向工程 2013-08-10 01:13:29
我打开一个IE浏览器,把浏览器全屏,然后运行下面的代码,代表应该在左上角单击,然后浏览器窗口弹出系统菜单。但实际下面的代码没有任何反应

#include<iostream>
#include<Windows.h>
using namespace std;

void main()
{
Sleep(3000);

INPUT ip;
ZeroMemory(&ip, sizeof(ip));
ip.type = INPUT_MOUSE;
ip.mi.dx = ip.mi.dy = 0;

int a = SendInput(1, &ip, sizeof(INPUT));
int b = a;

Sleep(3000);
}
...全文
588 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
谁学逆向工程 2013-08-14
  • 打赏
  • 举报
回复
引用 6 楼 zgl7903 的回复:
我测试的可以啊
你这个鼠标到是过去了,但是没出来菜单是怎么回事,单击应出来菜单啊
zgl7903 2013-08-14
  • 打赏
  • 举报
回复
我测试的可以啊

#include <crtdbg.h>

int _tmain(int argc, _TCHAR* argv[])
{  
  INPUT ip = {0};
  ip.type = INPUT_MOUSE;
  ip.mi.dx = ip.mi.dy = 0;
  ip.mi.dwFlags =  MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE; 
  
  if(SendInput(1, &ip, sizeof(INPUT)) != 1)
  {
    _ASSERT(0);
  }

  return 0;
}
CTRL + F5
谁学逆向工程 2013-08-14
  • 打赏
  • 举报
回复
引用 4 楼 zgl7903 的回复:
少了一个标志 ip.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
没反应
谁学逆向工程 2013-08-14
  • 打赏
  • 举报
回复
引用 9 楼 VisualEleven 的回复:
INPUT ip;
	ZeroMemory(&ip, sizeof(ip));
	ip.type = INPUT_MOUSE;
	ip.mi.dx = ip.mi.dy = 10;
	ip.mi.dwExtraInfo = 0;
	ip.mi.mouseData = 0;
	ip.mi.time = 0;
	ip.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN;
	SendInput(1, &ip, sizeof(INPUT));
你这个好使,但是有没有不移动鼠标的方法
Eleven 2013-08-14
  • 打赏
  • 举报
回复
需要先把鼠标移动过去,然后再模拟点击,也可以这样:

POINT pt = {0};
	GetCursorPos(&pt);
	
	INPUT ip;
	ZeroMemory(&ip, sizeof(ip));
	ip.type = INPUT_MOUSE;
	ip.mi.dx = ip.mi.dy = 10;
	ip.mi.dwExtraInfo = 0;
	ip.mi.mouseData = 0;
	ip.mi.time = 0;
	ip.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN;

	SetCursorPos(10, 10);
	SendInput(1, &ip, sizeof(INPUT));
	SetCursorPos(pt.x, pt.y);
Eleven 2013-08-14
  • 打赏
  • 举报
回复
INPUT ip;
	ZeroMemory(&ip, sizeof(ip));
	ip.type = INPUT_MOUSE;
	ip.mi.dx = ip.mi.dy = 10;
	ip.mi.dwExtraInfo = 0;
	ip.mi.mouseData = 0;
	ip.mi.time = 0;
	ip.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN;
	SendInput(1, &ip, sizeof(INPUT));
zgl7903 2013-08-14
  • 打赏
  • 举报
回复
鼠标点击的操作 再增加相应的标志 MSDN上都有说明 MOUSEEVENTF_ABSOLUTE Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section. MOUSEEVENTF_MOVE Specifies that movement occurred. MOUSEEVENTF_LEFTDOWN Specifies that the left button is down. MOUSEEVENTF_LEFTUP Specifies that the left button is up. MOUSEEVENTF_RIGHTDOWN Specifies that the right button is down. MOUSEEVENTF_RIGHTUP Specifies that the right button is up. MOUSEEVENTF_MIDDLEDOWN Specifies that the middle button is down. MOUSEEVENTF_MIDDLEUP Specifies that the middle button is up. MOUSEEVENTF_WHEEL Windows NT: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData
zgl7903 2013-08-13
  • 打赏
  • 举报
回复
少了一个标志 ip.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
zgl7903 2013-08-13
  • 打赏
  • 举报
回复
ip.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
谁学逆向工程 2013-08-12
  • 打赏
  • 举报
回复
引用 1 楼 szyyjzy 的回复:
错开点位置试试,比如 ip.mi.dx = ip.mi.dy = 10;
没反应
szyyjzy 2013-08-12
  • 打赏
  • 举报
回复
错开点位置试试,比如 ip.mi.dx = ip.mi.dy = 10;

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧