c# – 无法以编程方式查看光标的移动

确实在那里,经过一些研究并尝试了很多例子之后 –

Moving mouse cursor programmatically

How to move mouse cursor using C#?

Getting mouse position in c#

Control the mouse cursor using C#

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

变得沮丧我要求你们帮忙.

我正在尝试以编程方式移动光标(在控制台应用程序中,c#).

– &GT当我读到改变的位置似乎很好 – 但我实际上看不出差异.光标的图像停留在同一个地方……

我想实际看到光标在它改变的位置

谢谢

编辑2:谢谢所有人的帮助,目前我只是继续工作而没有看到光标移动到任何地方……所以很难获得有关它的位置的任何反馈(只是猜测).

解决方法:

我真的没有看到任何问题,这是一个测试代码,它适用于我(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.

它做到了这一点

上一篇:Windows10如何开启鼠标显示指针轨迹


下一篇:对象键