3#include "InputDeviceWindows.h"
6#include <QSharedPointer>
7#include <QLoggingCategory>
9Q_DECLARE_LOGGING_CATEGORY(logDW)
11QSharedPointer<CInputDevice> CInputDevice::GenerateObject()
16CInputDeviceWindows::CInputDeviceWindows() :
CInputDevice()
20CInputDeviceWindows::~CInputDeviceWindows()
22 qDebug(logDW,
"CInputDeviceX11::~CInputDeviceX11");
25int CInputDeviceWindows::KeyEvent(quint32 keysym, quint32 keycode,
bool down)
30int CInputDeviceWindows::MouseEvent(MouseButtons buttons, QPoint pos)
33 DWORD flags = MOUSEEVENTF_ABSOLUTE;
36 if (m_LastPostion != pos)
37 flags |= MOUSEEVENTF_MOVE;
42 if (::GetSystemMetrics(SM_SWAPBUTTON)) {
43 buttons = (buttons & ~(LeftButton | RightButton));
44 if (buttons & LeftButton) buttons |= LeftButton;
45 if (buttons & RightButton) buttons |= RightButton;
49 if((m_LastButtons & LeftButton) != (LeftButton & buttons))
51 if(buttons & LeftButton)
52 flags |= MOUSEEVENTF_LEFTDOWN;
54 flags |= MOUSEEVENTF_LEFTUP;
58 if((m_LastButtons & MiddleButton) != (MiddleButton & buttons))
60 if(buttons & MiddleButton)
61 flags |= MOUSEEVENTF_MIDDLEDOWN;
63 flags |= MOUSEEVENTF_MIDDLEUP;
67 if((m_LastButtons & RightButton) != (RightButton & buttons))
69 if(buttons & RightButton)
70 flags |= MOUSEEVENTF_RIGHTDOWN;
72 flags |= MOUSEEVENTF_RIGHTUP;
76 DWORD mouseWheelValue = 0;
77 if(UWheelButton & buttons)
79 flags |= MOUSEEVENTF_WHEEL;
80 mouseWheelValue = 120;
82 if(DWheelButton & buttons)
84 flags |= MOUSEEVENTF_WHEEL;
85 mouseWheelValue = -120;
87 if(LWheelButton & buttons)
89 flags |= MOUSEEVENTF_HWHEEL;
90 mouseWheelValue = 120;
92 if(RWheelButton & buttons)
94 flags |= MOUSEEVENTF_HWHEEL;
95 mouseWheelValue = -120;
99 m_LastButtons = buttons;
122 QRect primaryDisplay(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
126 if (primaryDisplay.contains(pos)) {
127 qDebug(logDW,
"In primary screen");
131 scaled.setX((pos.x() * 65535) / (primaryDisplay.width() - 1));
132 scaled.setY((pos.y() * 65535) / (primaryDisplay.height() - 1));
133 ::mouse_event(flags, scaled.x(), scaled.y(), mouseWheelValue, 0);
139 evt.type = INPUT_MOUSE;
140 QPoint vPos(pos.x() - GetSystemMetrics(SM_XVIRTUALSCREEN),
141 pos.y() - GetSystemMetrics(SM_YVIRTUALSCREEN));
142 evt.mi.dx = (vPos.x() * 65535) / (GetSystemMetrics(SM_CXVIRTUALSCREEN)-1);
143 evt.mi.dy = (vPos.y() * 65535) / (GetSystemMetrics(SM_CYVIRTUALSCREEN)-1);
144 evt.mi.dwFlags = flags | MOUSEEVENTF_VIRTUALDESK;
145 evt.mi.dwExtraInfo = 0;
146 evt.mi.mouseData = mouseWheelValue;
148 if (SendInput(1, &evt,
sizeof(evt)) != 1)
150 qCritical(logDW,
"SendInput fail: %d", GetLastError());
157int CInputDeviceWindows::MouseEvent(MouseButtons buttons,
int x,
int y)
159 return MouseEvent(buttons, QPoint(x, y));