使用mouse_even()模拟鼠标单击事件 [英] use mouse_even()to simulate mouse click event

查看:146
本文介绍了使用mouse_even()模拟鼠标单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码自动模拟鼠标单击事件.
某些对话框可以正常工作,但是某些带有TBitBtn按钮的按钮可以单击,只需将鼠标移到按钮区域,而无需执行其他任何操作.



I have used the following codes to simulate the mouse click event automatically.
Some dialogs can work well, but some button with TBitBtn button that can be clicked and just the mouse move to button area and no any other action.



x = rect.left * 65535/ GetSystemMetrics(SM_CXSCREEN);
y = rect.top * 65536 / GetSystemMetrics(SM_CYSCREEN);

::mouse_event(MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE, x+10, y+5, 0, 0);
				
				::mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
				::mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);



请帮我解决他的问题吗?

谢谢



please help me how to figure out his issue??

Thanks

推荐答案

此功能已被功能SendInput:
取代 http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms646310%28v=vs.85%29.aspx [
This function has been superseded by the function SendInput:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

I don''t say it will solve your problem, but with this function I never had any problems.

Your problem sounds rather strange. I would rather believe that you have miscalculated the click location or some other detail, but you did not provide enough information to pinpoint the problem. You can generate something based on exact coordinates, use your method and run target test application (not the one simulating the click) under the debugger, to check the coordinate.

I also must note, just in case: if, by any chance, you are using the simulation to write regular UI, it would be great abuse. However, there are cases where the user input simulation is important, for example, playing keyboard/mouse macro, creation of UI testing systems, etc.

—SA


感谢您的快速答复
我会尝试您的建议,并在以后提供您的反馈.
Thanks for your quick reply
I''ll try your suggestion and give your feedback later.


INPUT输入;
memset(&input,0x00,sizeof(INPUT));

input.type = INPUT_MOUSE;
input.mi.dx = vecBtnCords [i] .x + 800;
input.mi.dy = vecBtnCords [i] .y + 500;
input.mi.mouseData = 0;
input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
input.mi.time = 0;

SendInput(1,&input,sizeof(INPUT));

input.mi.dx = 0;
input.mi.dy = 0;
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;
input.mi.time = 0;
SendInput(1,&input,sizeof(INPUT));

SendInput(1,&input,sizeof(INPUT));



但是它仍然无法工作
INPUT input;
memset(&input, 0x00, sizeof(INPUT));

input.type = INPUT_MOUSE;
input.mi.dx = vecBtnCords[i].x+800;
input.mi.dy = vecBtnCords[i].y+500;
input.mi.mouseData = 0;
input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE;
input.mi.time = 0;

SendInput(1, &input, sizeof(INPUT));

input.mi.dx = 0;
input.mi.dy = 0;
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP;
input.mi.time = 0;
SendInput(1, &input, sizeof(INPUT));

SendInput(1, &input, sizeof(INPUT));



But it still cann''t work


这篇关于使用mouse_even()模拟鼠标单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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