using System; using System.Drawing; using System.Runtime.InteropServices; // The 'windowHandle' parameter will contain the window handle for the: // - Active window when run by hotkey // - Window Location target when run by a Window Location rule // - TitleBar Button owner when run by a TitleBar Button // - Jump List owner when run from a Taskbar Jump List // - Currently focused window if none of these match public static class DisplayFusionFunction { //overload this function to take an unsigned integer as pvParam to set the mouse speed [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni); //overload this function to output pvParam to an unsigned integer [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, out uint pvParam, uint fWinIni); //constants to get and set the mouse speed private const uint SPI_GETMOUSESPEED = 0x0070; private const uint SPI_SETMOUSESPEED = 0x0071; //constants to tell windows to update profile and windows private const uint SPIF_UPDATEINIFILE = 0x0001; private const uint SPIF_SENDWININICHANGE = 0x0002; public static void Run(IntPtr windowHandle) { //initialize a uint uint speed = 0; //get the mouse speed SystemParametersInfo(SPI_GETMOUSESPEED, 0, out speed, 0); //decrement the mouse speed and set it SystemParametersInfo(SPI_SETMOUSESPEED, 0, --speed, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); } }