自动禁用鼠标加速 - Windows
Automatically disable mouse acceleration - Windows
我有一台笔记本电脑,我经常用它搭配鼠标。我不喜欢在使用鼠标时加速。因此,每次插入鼠标时我都必须禁用加速。有没有办法在我插入鼠标时自动禁用鼠标加速?
我知道你可以在 udev 上做一个脚本,这样它就可以识别插入的鼠标并自动禁用鼠标加速......但我如何在 Windows 上做到这一点?
我相信这对于一个简单的批处理文件是不可能的。但是你可以在 c++ 中使用 Windows API:
您可以使用 RegisterDeviceNotification
注册设备通知(例如插入 USB 鼠标)
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
}
并在 window 的消息处理程序中收听它们 (LRESULT CALLBACK
WndProc
(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
实际上可以使用 SystemParametersInfo
as described in this excellent answer 来更改设置。
我实现了一个名为 accelSwitcher that does just that. It is available on github 的小工具。
我有一台笔记本电脑,我经常用它搭配鼠标。我不喜欢在使用鼠标时加速。因此,每次插入鼠标时我都必须禁用加速。有没有办法在我插入鼠标时自动禁用鼠标加速? 我知道你可以在 udev 上做一个脚本,这样它就可以识别插入的鼠标并自动禁用鼠标加速......但我如何在 Windows 上做到这一点?
我相信这对于一个简单的批处理文件是不可能的。但是你可以在 c++ 中使用 Windows API:
您可以使用 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
}
并在 window 的消息处理程序中收听它们 (LRESULT CALLBACK
WndProc
(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
实际上可以使用 SystemParametersInfo
as described in this excellent answer 来更改设置。
我实现了一个名为 accelSwitcher that does just that. It is available on github 的小工具。