Unable to see cursor movement programmatically

Well, after really conducted research and many examples -

Mouse cursor transition

How to move mouse cursor using C #?

Getting mouse position in C #

Control your mouse cursor with C #

http://www.blackwasp.co.uk/MoveMousePointer.aspx

and disappointed. I ask you guys for help.

I am trying to move the cursor programmatically (in a console application, C #).

Since I read the changed location, this seems fine, but I don't really see the difference. The cursor image remains in one place ...

I want to actually see the cursor at its changed location

thank

2: , , , , ... - ( ).

+4
1

, , (win7_64):

class Program
{
    [StructLayout(LayoutKind.Sequential)]
    public struct MousePoint
    {
        public int X;
        public int Y;
    }

    [DllImport("user32.dll", EntryPoint = "SetCursorPos")]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool SetCursorPos(int X, int Y);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool GetCursorPos(out MousePoint lpMousePoint);

    static void Main(string[] args)
    {
        ConsoleKey key;
        MousePoint point;
        while ((key = Console.ReadKey(true).Key) != ConsoleKey.Escape)
        {
            GetCursorPos(out point);
            if (key == ConsoleKey.LeftArrow)
                point.X -= 10;
            if (key == ConsoleKey.RightArrow)
                point.X += 10;
            if (key == ConsoleKey.UpArrow)
                point.Y -= 10;
            if (key == ConsoleKey.DownArrow)
                point.Y += 10;
            SetCursorPos(point.X, point.Y);
        }
    }
}

@Keith answer.


enter image description here

+3

Source: https://habr.com/ru/post/1547428/


All Articles