2013-03-27 94 views
0
if (i==0) 
{ 
//Here I've to do MouseDown operation 
} 
else 
{ 
//perform MouseUp operation 
} 

这是示例代码我WANN做事端像上面......鼠标点击操作VC++

我可以通过SetCursorPos移动鼠标()。所以,我怎么能执行单击事件

+1

为什么标记'opencv'?你究竟想达到什么目的? – LihO 2013-03-27 14:44:40

+0

我正在做类似使用Opencv库的虚拟鼠标...... – 2013-03-27 15:00:36

回答

0

可以使用SendInput WinAPI的功能(也有过时的mouse_event功能以及,我觉得这更容易使用,但不建议使用/替代标记)可以模拟任何形式的输入。

取决于你正在做什么,SendMessage(阻塞)或PostMessage(非阻塞)可能会更好/更易于使用,因为这些送通过直接输入事件产生的窗口消息。

0

那么,对于highgui窗口,试试这个来代替:

void onmouse(int event, int x, int y, int d, void *ptr) 
{ 
    // cache coords for use in main() 
    cv::Point * p = (cv::Point *)ptr; 
    p->x = x; 
    p->y = y; 

    if (event != 0) 
     cout << event << " " << x << " " << y << " " << d << " " << endl; 
} 
int main() 
{ 

    cv::namedWindow("win",1); 
    cv::Point p; 
    cv::SetMouseCallback("win",onmouse,(void*)(&p)); 
    ... 
    // whenever someone clicks or moves, the coords will be in p now