mouse_event()鼠标不动.米奇死了吗??? [英] mouse_event() Mouse does not move. Is mickey dead ???

查看:296
本文介绍了mouse_event()鼠标不动.米奇死了吗???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我的函数mouse_event()有问题.
我想将鼠标移到某个位置(例如x252 y87),然后在该位置双击.
我输入的坐标是屏幕的绝对坐标.
如果我对msdn的理解正确,那么我首先必须将我的坐标(指的是1280 x 800像素的resulotion)转换为鼠标坐标".
我不明白为什么它失败了.读取了mouse_event行,但是鼠标没有移动.编译时都没有错误.我之前曾将mouse_event与标志"MOUSEEVENTF_MOVE"一起使用,但没有出现问题.
有人对我有提示吗?

问候
SH


#include "windows.h"
#include "ocr.h"

using namespace std;
void sitdown(STATEOBJECTS *Places)
{

    // TO DO replace 1280 & 800 by current screen resolution
    int mousecoord = 65535;
    int screenx = 1280;
    int screeny = 800;
    double mouseVSpixelx = mousecoord/screenx;
    double mouseVSpixely = mousecoord/screeny;
    //If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute
    //coordinates between 0 and 65,535. The event procedure maps these coordinates onto
    //the display surface. Coordinate (0,0) maps onto the upper-left corner of the display
    //surface, (65535,65535) maps onto the lower-right corner.
    for(int k=0; k<6; k++)
    {
        if(Places[k].free=1)
        {
            int xini=Places -> coord.x;
            int yini=Places -> coord.y;
            unsigned long x = xini* mouseVSpixelx;
            unsigned long y = yini* mouseVSpixely;
            //Move mouse to "Places" position
            mouse_event(MOUSEEVENTF_ABSOLUTE,x,y,0,0);
             //send keystrokes doubleklick VK_LBUTTON twice fast=doubleklick
             keybd_event(VK_LBUTTON, VkKeyScan(VK_LBUTTON), 0, 0);              //press Leftmousebutton
             Sleep(15);                                                         //wait a little
             keybd_event(VK_LBUTTON, VkKeyScan(VK_LBUTTON), KEYEVENTF_KEYUP, 0);//release Leftmousebutton
             Sleep(15);
             keybd_event(VK_LBUTTON, VkKeyScan(VK_LBUTTON), 0, 0);              //press Leftmousebutton
             Sleep(15);                                                         //wait a little
             keybd_event(VK_LBUTTON, VkKeyScan(VK_LBUTTON), KEYEVENTF_KEYUP, 0);//release Leftmousebutton
        }
        Places++;
    }
}

解决方案

尝试使用SendInput API代替,您可以为坐标提供左键按下标志,然后向其提供左键按下标志.

blockquote>

谢谢你戴夫!

SendInput()起作用了!

干杯,

SH


Hello !

I''m having a problem with the function mouse_event().
I would like to move the mouse to a certain place (eg x252 y87) and then doubleklick at that location.
My input coordinates are absolute screen coordinates.
If I have understood msdn right, I at first have to convert my coordinates (refering to a 1280 by 800px resulotion) to "mouse coordinates".
I do not understand why it fails. The mouse_event line is read, but the mouse does not move. No errors while compiling either. I have used mouse_event before with the flag "MOUSEEVENTF_MOVE" that did work without problems.
Anyone has a hint for me?

Regards
SH


#include "windows.h"
#include "ocr.h"

using namespace std;
void sitdown(STATEOBJECTS *Places)
{

    // TO DO replace 1280 & 800 by current screen resolution
    int mousecoord = 65535;
    int screenx = 1280;
    int screeny = 800;
    double mouseVSpixelx = mousecoord/screenx;
    double mouseVSpixely = mousecoord/screeny;
    //If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute
    //coordinates between 0 and 65,535. The event procedure maps these coordinates onto
    //the display surface. Coordinate (0,0) maps onto the upper-left corner of the display
    //surface, (65535,65535) maps onto the lower-right corner.
    for(int k=0; k<6; k++)
    {
        if(Places[k].free=1)
        {
            int xini=Places -> coord.x;
            int yini=Places -> coord.y;
            unsigned long x = xini* mouseVSpixelx;
            unsigned long y = yini* mouseVSpixely;
            //Move mouse to "Places" position
            mouse_event(MOUSEEVENTF_ABSOLUTE,x,y,0,0);
             //send keystrokes doubleklick VK_LBUTTON twice fast=doubleklick
             keybd_event(VK_LBUTTON, VkKeyScan(VK_LBUTTON), 0, 0);              //press Leftmousebutton
             Sleep(15);                                                         //wait a little
             keybd_event(VK_LBUTTON, VkKeyScan(VK_LBUTTON), KEYEVENTF_KEYUP, 0);//release Leftmousebutton
             Sleep(15);
             keybd_event(VK_LBUTTON, VkKeyScan(VK_LBUTTON), 0, 0);              //press Leftmousebutton
             Sleep(15);                                                         //wait a little
             keybd_event(VK_LBUTTON, VkKeyScan(VK_LBUTTON), KEYEVENTF_KEYUP, 0);//release Leftmousebutton
        }
        Places++;
    }
}

解决方案

try using the SendInput API instead, you can provide the coordinates with a left button down flag followed by one with a left button up flag.


Thank You Dave!

SendInput() worked !

Cheers,

SH


这篇关于mouse_event()鼠标不动.米奇死了吗???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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