简体   繁体   English

在C#中获取鼠标光标速度

[英]Getting the mouse cursor speed in C#

I was sucecssful regarding changing the mouse speed with C# with the help of this article: http://www.sparrowtail.com/changing-mouse-pointer-speed-c . 在本文的帮助下,我对使用C#更改鼠标速度非常满意: http : //www.sparrowtail.com/changing-mouse-pointer-speed-c

Now I also want to get the current mouse speed. 现在我也想获得当前的鼠标速度。 I tried to change const uint SPI_GETMOUSESPEED to 0x0072 and also to 0x0070 hoping that this would be the right adress. 我试图改变const uint SPI_GETMOUSESPEED0x0072并且还0x0070希望这将是正确的ADRESS。 Microsoft documentation says that the adress (at least in C++) is 0x70 however it is not possbile for me to get the right adress on the internet. Microsoft文档说地址(至少在C ++中)为0x70但是我不可能在Internet上获得正确的地址。

My function: 我的功能:

private int GetMouseSpeed()
    {

        const uint SPI_GETMOUSESPEED = 0x0070;
        uint mouseSpeed = 0;

        SystemParametersInfo
        (
            SPI_GETMOUSESPEED,
            0,
            mouseSpeed,
            0
        );

        return (int) mouseSpeed;
    }

You can find all possible values of uiAction on the MSDN . 您可以在MSDN上找到uiAction所有可能值。 SPI_GETMOUSESPEED value is 0x70 . SPI_GETMOUSESPEED值为0x70 Plus, you need to pass pointer to an integer that receives a value. 另外,您需要将指针传递给接收值的整数。 In the code below I did it using the unsafe & operator. 在下面的代码中,我使用了不安全的&运算符。 In order to compile it, you need to check Allow unsafe context in the build settings of your project. 为了进行编译,您需要在项目的构建设置中选中“ Allow unsafe context ”。

public const UInt32 SPI_GETMOUSESPEED = 0x0070;

[DllImport("User32.dll")]
static extern Boolean SystemParametersInfo(
    UInt32 uiAction,
    UInt32 uiParam,
    IntPtr pvParam,
    UInt32 fWinIni);

static unsafe void Main(string[] args)
{
    int speed;
    SystemParametersInfo(
        SPI_GETMOUSESPEED,
        0,
        new IntPtr(&speed),
        0);
    Console.WriteLine(speed);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM