Control mouse pointer with Qt even outside the Qt application.



  • Hi all, first let me explain the plot, i have been building an application that can emulate the functions of a mouse using hand gestures. I did the gesture recognition part using OpenCV. I am trying to make a GUI interface using Qt.

    As an initial step, I am currently trying to control the mouse using the keyboard. I assigned the keys A W D S to move the mouse in all the directions using
    void QCursor::setPos ( int x, int y ). Its working fine.

    Then i used the windows API function:
    mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 1, 1, 0, 0);
    to simulate the mouse click.

    Its is also working but when i click anywhere outside the Qt application the focus shifts and i loose control of the mouse through the keyboard. Is there any remedy for this?



  • If you already use Win32 Api, you can force the focus calling SetFocus.



  • i tried to set the focus using

    SetFocus(GetActiveWindow());

    but there was no success. The control jumps to the next window onto which i click using my 'O' key(i have assigned O Key to perform single click). Any remedy for this?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.