Automatically disable mouse acceleration - Windows

4.6k views Asked by At

I have a laptop and I often use a mouse with it. I don't like acceleration while using the mouse. Thus I have to disable the acceleration every time I plug the mouse. Is there a way to automatically disable mouse acceleration, whenever I plug my mouse? I know that u can do a script un udev so it recognizes mouse plugged and auto disable mouse acceleration... but how do i do it on Windows ?

1

There are 1 answers

0
jan-glx On BEST ANSWER

I believe this is not possible with a simple batch-file. However you can use the Windows API in c++:

You can register for device notifications (like plugging in an USB mouse) using RegisterDeviceNotification

HANDLE hRecipient = hWnd; // your window handle as returned by CreateWindow

GUID InterfaceClassGuid = { 0x378de44c, 0x56ef, 0x11d1, 0xbc, 0x8c, 0x00, 0xa0, 0xc9, 
                            0x14, 0x05, 0xdd }; // GUID_DEVINTERFACE_MOUSE
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;

ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = InterfaceClassGuid;

HDEVNOTIFY hDeviceNotify = RegisterDeviceNotification(hRecipient, &NotificationFilter, 
                                                      DEVICE_NOTIFY_WINDOW_HANDLE);
if (hDeviceNotify == NULL) {
    GetLastError(); // do error handling here
}

and listen to them in your window's message handler (LRESULT CALLBACKWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam))

switch (message)
{
case WM_DEVICECHANGE:
    switch (wParam)
    {
    case DBT_DEVICEARRIVAL:
        // Mouse plugged in - turn mouse acceleration off here
        break;
    case DBT_DEVICEREMOVECOMPLETE:
        // Mouse removed - turn mouse acceleration on here
        break;
    default:
        break;
    }
    break;
case // ... your usual window message handling

actually changing the setting can be achieved using SystemParametersInfo as described in this excellent answer.


I implemented a tiny tool called accelSwitcher that does just that. It is available on github.