0

I am currently working on a dual monitor system where the secondary monitor is virtual. My requirements are that I connect to this via Teamviewer and run a customer application on the secondary screen which will control the mouse cursor on the primary. At this stage no code exists and I am just trying to wrap my head around what needs to be done.

My issue is that the coordinates seem to begin at the secondary screen and extend positively onto the primary and negatively onto the primary screens ( see screenshot of a mouse tracking app with the cursor on the primary screen)

I am able to work with the mouse in positive coordinates but trying to move to the left of the secondary screen requires x to be below 0. Can anyone suggest how I can work with this?

Gareth France
  • 53
  • 3
  • 5
  • Perhaps add the width of the left screen to all X coordinates...? Then you have a coordinate system starting at the top left of the left screen – canton7 Mar 19 '21 at 11:33
  • The goal of the question is not very clear. Desktops are in principle just non overlapping rectangles on a coordinate grid. If coordinates are negative or positive should not matter at all. Are you asking how to map coordinates from one rectangle to another? – JonasH Mar 19 '21 at 11:40
  • Read the notes here: [Using SetWindowPos with multiple monitors](https://stackoverflow.com/a/53026765/7444103) – Jimi Mar 19 '21 at 11:46
  • @JonasH the goal of the question is to move the mouse cursor to the left of coordinate 0,0. – Gareth France Mar 19 '21 at 11:51
  • @Jimi thank you for that, it seems to match my issue perfectly. However I am still unsure as to how I may move the mouse cursor into the negative space. – Gareth France Mar 19 '21 at 11:52
  • It's not *negative space* :) Just values below zero. You can move the Cursor to any position in the VirtualScreen. With, e.g., `Cursor.Position = new Point([X], [Y]);`. See the bounding rectangle of the Screen where you want to move the Mouse Pointer, the add an offset as usual. The Offset of the PrimaryScreen is (0, 0). Your Screen offset will be, e.g. (-1280, 0). To move the Cursor in the middle of it, then set, e.g., `Cursor.Position = new Point(-640, 400);`. Anyway, see what is the bounding rectangle of that Screen and use its offset as reference. – Jimi Mar 19 '21 at 12:03

1 Answers1

0

Whilst experimenting with basic mouse movement routines found online I was using this:

private void MoveCursor(int xpos, int ypos)
    {
        // Set the Current cursor, move the cursor's Position,
        // and set its clipping rectangle to the form. 

        this.Cursor = new Cursor(Cursor.Current.Handle);
        Cursor.Position = new Point(xpos, ypos);
        //Cursor.Clip = new Rectangle(this.Location, this.Size);
    }

and discovered that the cursor.clip line I have commented out was for whatever reason forcing the cursor to remain on the primary screen. Thanks everyone.

Gareth France
  • 53
  • 3
  • 5