Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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#_.net Core_Console Application - Fatal编程技术网

C# 如何设置系统鼠标双击速度

C# 如何设置系统鼠标双击速度,c#,.net-core,console-application,C#,.net Core,Console Application,我正在构建一个DotnetCore3.1控制台应用程序,在这里我想获取并设置系统的鼠标双击速度 我成功地获得了速度使用 [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern int GetDoubleClickTime(); 但无法为相同的设置所需的值 我尝试了以下选项,但没有成功 设置双击时间 从上述方法接收当前系统值

我正在构建一个DotnetCore3.1控制台应用程序,在这里我想获取并设置系统的鼠标双击速度

我成功地获得了速度使用

 [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int GetDoubleClickTime();
但无法为相同的设置所需的值

我尝试了以下选项,但没有成功

  • 设置双击时间
    • 从上述方法接收当前系统值
    • 将200作为要修改的Arg1值传递
    • 接收到以下方法的输出为true,但值未更改
    实施:

    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
         static extern bool SetDoubleClickTime(uint Arg1);
    
    [DllImport("User32.dll")]
            static extern bool SystemParametersInfo(int uiAction, int uiParam, IntPtr ipParam, int fWinIni);
    
     var result= SystemParametersInfo(20, 200, IntPtr.Zero, 2);
    
  • 系统参数信息
    • 我也尝试过使用SystemParametersInfo
    • 接收到以下方法的输出为true,但值未更改
    实施:

    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
         static extern bool SetDoubleClickTime(uint Arg1);
    
    [DllImport("User32.dll")]
            static extern bool SystemParametersInfo(int uiAction, int uiParam, IntPtr ipParam, int fWinIni);
    
     var result= SystemParametersInfo(20, 200, IntPtr.Zero, 2);
    

    这一个对我有效,即使是低至100ms的值。设置后是否尝试
    GetDoubleClickTime()
    检查您的值是否已实际设置

    using System;
    using System.Runtime.InteropServices;
    
    class Program
    {
        [DllImport("user32.dll")]
        public static extern int GetDoubleClickTime();
        [DllImport("user32.dll")]
        public static extern bool SetDoubleClickTime(uint Arg1);
    
        public static void Main()
        {
            var time = GetDoubleClickTime();
            Console.WriteLine(time);
            SetDoubleClickTime(4200);
            time = GetDoubleClickTime();
            Console.WriteLine(time);
        }
    }
    

    只是旁注;操作系统的时钟有一些限制,所以一些小值可能不起作用。我尝试过使用500-5000之间的多个值,但没有得到任何一个值的反映。谢谢你的回答。但这并不正常。在设置DoubleClickTime之后,通过调用GetDoubleClickTime,您将获得应用的更改。但相同的值将不会应用于我在图像中显示的mose设置页面a。当你再次启动你的控制台时,你会意识到设置没有被应用。user32.dll改变设置的方法是一个快速的黑客,不需要注销和重新启动就可以做到这一点。实际值存储在注册表中的“HKCU:\Control Panel\Mouse”下,因此您需要修改DoubleClickSpeed键以实现持久性。这就是鼠标设置页面获取值的地方。我知道通过注册表进行更改的方法。但我计划忽略直接的注册表修改。但现在我相信我将不得不这么做。非常感谢。