C++ で現在のマウスの dpi 設定を取得する方法はありますか?
問題は、マウス移動メッセージをシステムに送信すると、マウスの dpi 解像度に応じて異なるカーソル位置になることです。
編集:
マウスからの dpi 設定を必要としない解決策を見つけました。SystemParametersInfo でマウスの速度を取得し、moveDistance.x * 5.0 / mouseSpeed で移動距離を計算します。5.0 / mouseSpeed は、移動距離が常に正しいことを保証するマジック ナンバーです。
// get mouse speed
int mouseSpeed;
mouseSpeed = 0;
SystemParametersInfo(SPI_GETMOUSESPEED, 0, &mouseSpeed, 0);
// calculate distance to gaze position
POINT moveDistance;
moveDistance.x = m_lastEyeX - m_centerOfScreen.x;
moveDistance.y = m_lastEyeY - m_centerOfScreen.y;
// 5.0 / mouseSpeed -> magic numbers, this will halve the movedistance if mouseSpeed = 10, which is the default setting
// no need to get the dpi of the mouse, but all mouse acceleration has to be turned off
double xMove = moveDistance.x * 5.0 / static_cast<double>(mouseSpeed);
double yMove = moveDistance.y * 5.0 / static_cast<double>(mouseSpeed);
INPUT mouse;
memset(&mouse, 0, sizeof(INPUT));
mouse.type = INPUT_MOUSE;
// flag for the mouse hook to tell that it's a synthetic event.
mouse.mi.dwExtraInfo = 0x200;
mouse->mi.dx = static_cast<int>(xMove);
mouse->mi.dy = static_cast<int>(yMove);
mouse->mi.dwFlags = mouse->mi.dwFlags | MOUSEEVENTF_MOVE;
SendInput(1, &mouse, sizeof(mouse));
これが誰かに役立つことを願っています:)