SetCursorPos API not allowing to draw over snipping tool with pen or highlight even if correct mouse coordinates are provided,

SK_123 1 Reputation point
2021-02-25T12:18:43.327+00:00

I use SetCursorPos to set mouse coordinates over remote Desktop. and the use mouse_event API to provide appropriate flag and wheel info: ::SetCursorPos(x,y); ::mouse_event(flags, 0, 0, wheel_movement, 0); It is not allowing to draw over snipping tool with pen or highlight or Move the multiple monitor position from display settings or Move the scroll bar with left mouse click on Internet explorer.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,474 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,594 questions
{count} votes

2 answers

Sort by: Most helpful
  1. SK_123 1 Reputation point
    2021-02-26T11:23:29.007+00:00

    Yes I need to send mouse coordinates to remote desktop.So doing like, setting the mouse coordinates that is sent from viewer to remote desktop via "SetCursorPos" and mouse related flag and other details via "mouse_events" or "SendInput".
    But by doing this some application like "Drawing on snipping tool" by left click mouse move not able to accomplish.

    Cannot send mouse coordinates via "mouse_events" or "SendInput" directly because it causes problem in case of more than one monitor is present.(need to calculate for each monitor, but can have n number of monitor).

    0 comments No comments

  2. Drake Wu - MSFT 991 Reputation points
    2021-03-01T09:56:10.277+00:00

    Hi @SK_123 I cannot reproduce the problem you mentioned. I can directly use SendInput on the remote desktop to draw points or lines on the snipping tool.

    #include <windows.h>  
    #include <iostream>  
    using namespace std;  
      
    void clickFromTo(int x, int y,int w,int h) {  
        INPUT click[3] = {};  
      
        click[0].type = INPUT_MOUSE;  
        click[0].mi.dwFlags = MOUSEEVENTF_MOVE| MOUSEEVENTF_LEFTDOWN| MOUSEEVENTF_ABSOLUTE;// Release the mouse before moving it  
      
      
        DWORD fScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);  
        DWORD fScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);  
        click[1].type = INPUT_MOUSE;  
        click[0].mi.dx = click[1].mi.dx = MulDiv(x, 65535, fScreenWidth);  
        click[0].mi.dy = click[1].mi.dy = MulDiv(y, 65535, fScreenHeight);  
        click[2].mi.dx = MulDiv(x + w, 65535, fScreenWidth);  
        click[2].mi.dy = MulDiv(y + h, 65535, fScreenHeight);  
        click[1].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;  
      
        click[2].type = INPUT_MOUSE;  
        click[2].mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;  
      
        SendInput(3, click, sizeof(INPUT));  
    }  
    void mouseClick() {  
        INPUT click[2] = {};  
      
        click[0].type = INPUT_MOUSE;  
        click[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;  
          
        click[1].type = INPUT_MOUSE;  
        click[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;  
        SendInput(2, click, sizeof(INPUT));  
    }  
    int main()  
    {  
        clickFromTo(2200, 500, 50, 50);  
        //SetCursorPos(2200, 500);  
        //mouseClick();  
    }  
    

    72965-1.png

    Are the coordinates you use only relative to the remote desktop coordinates or based on this virtual screen? If it is relative For remote desktop coordinates, the corresponding virtual screen coordinates should be calculated first.


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.