Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在光标位于屏幕边界时移动物理鼠标时获取鼠标或移动/位置_C#_Wpf_Cursor_Mouse - Fatal编程技术网

C# 在光标位于屏幕边界时移动物理鼠标时获取鼠标或移动/位置

C# 在光标位于屏幕边界时移动物理鼠标时获取鼠标或移动/位置,c#,wpf,cursor,mouse,C#,Wpf,Cursor,Mouse,社区 对于我当前的项目C,WPF,VS 16.5.3,W10 1909,我需要识别鼠标移动,即使光标位于屏幕边框,即右上角,并且用户继续移动鼠标。 当我要求得到这个职位时 Mouse.GetPosition(Application.Current.MainWindow) 当光标位于屏幕边框时,如果我继续移动物理鼠标,我将获得屏幕内的位置,并且值将停止更改。我想要的是一个虚拟的无限屏幕,从中我可以得到鼠标光标的坐标,其他想法也很受欢迎。 我如何做到这一点 谢谢你的努力。不幸的是,这实现了与我al

社区

对于我当前的项目C,WPF,VS 16.5.3,W10 1909,我需要识别鼠标移动,即使光标位于屏幕边框,即右上角,并且用户继续移动鼠标。 当我要求得到这个职位时

Mouse.GetPosition(Application.Current.MainWindow)
当光标位于屏幕边框时,如果我继续移动物理鼠标,我将获得屏幕内的位置,并且值将停止更改。我想要的是一个虚拟的无限屏幕,从中我可以得到鼠标光标的坐标,其他想法也很受欢迎。 我如何做到这一点


谢谢你的努力。不幸的是,这实现了与我allready相同的结果:它在窗口之外工作,但不在屏幕边界之外。此外,作为对您的提示:您可以通过两行代码获得相同的结果:Application.Current.MainWindow.CaptureMouse;Point mousPosition=Mouse.GetPositionApplication.Current.MainWindow;你给我指出了一个不错的解决方法:移动鼠标器几个像素后,我会将光标重置到初始位置并测量移动距离。对于这个应用程序,它不会损害用户体验,因为光标是不可见的。我不能认为你的答案是正确的,但无论如何我会投赞成票。
    using System;
    using System.Runtime.InteropServices;

    namespace StackOverFlow
    {
        public class Program
        {
            [DllImport("user32.dll")]
            static extern bool GetCursorPos(out POINT lpPoint);

            public struct POINT
            {
                public int X;
                public int Y;
            }

            static int _x, _y;

            static void ShowMousePosition()
            {
                POINT point;
                if (GetCursorPos(out point) && point.X != _x && point.Y != _y)
                {
                    Console.Clear();
                    Console.WriteLine("({0},{1})", point.X, point.Y);
                    _x = point.X;
                    _y = point.Y;
                }
            }

            static void Main()
            {
                while (true)
                {
                    ShowMousePosition();
                }
            }
        }
    }