没有焦点的SetCursorPos和mouse_event? [英] SetCursorPos and mouse_event without focus?

查看:254
本文介绍了没有焦点的SetCursorPos和mouse_event?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





打扰一下我的英语水平不好,我是法国学生



我用我的光标在应用程序的按钮上自动开发一个c ++应用程序用于移动和clic,它不能支持命令行,但只支持GUI。



使用windows.h,我测试了这个:

 SetCursorPos(X,Y); 
睡眠( 500 );
Mouse_event(MOUSEEVENTF_LEFTDOWN, 0 0 0 0 );
睡眠( 500 );
mouse_event(MOUSEEVENTF_LEFTUP, 0 0 0 0 );





我的代码控制台应用程序仅在前台(焦点)工作时才会工作

因此,如果我的控制台应用程序没有聚焦,我的鼠标就无法移动..



你是解决这个问题的解决方案吗?





祝你好运
$ b $bSébastienFAVIER

解决方案

鼠标与焦点无关。使用函数 SendInput

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx [ ^ ]。



该功能是低级别的;它作为原始鼠标和键盘事件来自设备驱动程序。

不要使用函数 mouse_event keybd_event ;它们已被 SendInput 取代。



-SA


鼠标属于前景窗口,因此更改仅在那里工作。您可以使用 TrackMouseEvent功能跟踪鼠标。对于每个跟踪周期,您必须再次调用它!



要在Windows激活时获得通知,您必须处理 WM_ACTIVATE消息


感谢您的回复! :-)

我会测试这个,我随时通知你



祝你好运
$ b $bSébastienFAVIER

Hi,

Excuse me for my bad english level, i'm french student

I develop a c++ application for move and clic automatically on application's buttons with my cursor who can't support command line, but GUI only.

With windows.h, I tested this:

SetCursorPos(X,Y);
Sleep(500);
Mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(500);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);



This code of my console application work only if is in foreground ( focused )
So if my console application has not focus, my mouse can't move..

Are you solution for resolve this?


Best regards
Sébastien FAVIER

解决方案

Mouse has nothing to do with focus. Use the function SendInput:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

The function is low-level; it works as the raw mouse and keyboad events came from the device driver.
Don't use the functions mouse_event and keybd_event; they have been superseded with SendInput.

—SA


The mouse belongs the foreground windows, so changes work only there. You can track the mouse with TrackMouseEvent function. For every tracking cycle you must call it again!!!

To get informed when your windows is activated you must handle the WM_ACTIVATE message.


Thank you for your reply! :-)
I will test this, I keep you informed

Best regards
Sébastien FAVIER


这篇关于没有焦点的SetCursorPos和mouse_event?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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