Search code examples
c#winformspanel

Dynamically changing Mouse speed


Guys, I have a C# Winforms application with a panel inside the form. What I want to do is, whenever the mouse pointer enters this panel, I want to slow the movement speed of the mouse by 50%. Once the pointer moves outside this panel, I want to speed of the mouse to resume normal 100% speed. How can I accomplish this in C#?


Solution

  • This article might help

    Here's the code from the article:

    using System;
    using System.Runtime.InteropServices;
    
    namespace MouseSpeedSwitcher
    {
        class Program
        {
            public const UInt32 SPI_SETMOUSESPEED = 0x0071;
    
            [DllImport("User32.dll")]
            static extern Boolean SystemParametersInfo(
                UInt32 uiAction, 
                UInt32 uiParam, 
                UInt32 pvParam,
                UInt32 fWinIni);
    
            static void Main(string[] args)
            {
                SystemParametersInfo(
                    SPI_SETMOUSESPEED, 
                    0, 
                    uint.Parse(args[0]), 
                    0);
            }
        }
    }