#ifdef Q_WS_WIN
# include <windows.h>
# include <shellapi.h>
#else /* Q_WS_X11 */
# include <X11/Xlib.h>
#endif
#include <qpaintdevice.h>
// Implement a way to easily deduce which mousebuttons and modifier
// keys are held down
static Qt::ButtonState get_modifiers()
{
int result = Qt::NoButton;
#ifdef Q_WS_WIN
result |= GetAsyncKeyState(VK_SHIFT) < 0 ? Qt::ShiftButton : 0;
result |= GetAsyncKeyState(VK_MENU) < 0 ? Qt::AltButton : 0;
result |= GetAsyncKeyState(VK_CONTROL) < 0 ? Qt::ControlButton : 0;
// Check if left and right mousebuttons have been swapped
bool swap_buttons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
if (swap_buttons)
{
result |= GetAsyncKeyState(VK_LBUTTON) < 0 ? Qt::RightButton : 0;
result |= GetAsyncKeyState(VK_RBUTTON) < 0 ? Qt::LeftButton : 0;
}
else
{
result |= GetAsyncKeyState(VK_LBUTTON) < 0 ? Qt::LeftButton : 0;
result |= GetAsyncKeyState(VK_RBUTTON) < 0 ? Qt::RightButton : 0;
}
result |= GetAsyncKeyState(VK_MBUTTON) < 0 ? Qt::MidButton : 0;
#else /* Q_WS_X11 */
Window root, child;
int root_x, root_y;
int win_x, win_y;
uint keys_buttons;
&root, &child,
&root_x, &root_y,
&win_x, &win_y,
&keys_buttons);
if (status)
{
result |= keys_buttons & ShiftMask ? Qt::ShiftButton : 0;
result |= keys_buttons & Mod1Mask ? Qt::AltButton : 0;
result |= keys_buttons & Mod4Mask ? Qt::MetaButton : 0;
result |= keys_buttons & ControlMask ? Qt::ControlButton : 0;
result |= keys_buttons & Button1Mask ? Qt::LeftButton : 0;
result |= keys_buttons & Button2Mask ? Qt::MidButton : 0;
result |= keys_buttons & Button3Mask ? Qt::RightButton : 0;
}
#endif
return Qt::ButtonState(result);
}
Qt::ButtonState MyApplication::keyboardModifiers()
{
return Qt::ButtonState(get_modifiers() & Qt::KeyButtonMask);
}
Qt::ButtonState MyApplication::mouseButtons()
{
return Qt::ButtonState(get_modifiers() & Qt::MouseButtonMask);
}
#ifdef Q_WS_WIN
# include <windows.h>
# include <shellapi.h>
#else /* Q_WS_X11 */
# include <X11/Xlib.h>
#endif
#include <qpaintdevice.h>
// Implement a way to easily deduce which mousebuttons and modifier
// keys are held down
static Qt::ButtonState get_modifiers()
{
int result = Qt::NoButton;
#ifdef Q_WS_WIN
result |= GetAsyncKeyState(VK_SHIFT) < 0 ? Qt::ShiftButton : 0;
result |= GetAsyncKeyState(VK_MENU) < 0 ? Qt::AltButton : 0;
result |= GetAsyncKeyState(VK_CONTROL) < 0 ? Qt::ControlButton : 0;
// Check if left and right mousebuttons have been swapped
bool swap_buttons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
if (swap_buttons)
{
result |= GetAsyncKeyState(VK_LBUTTON) < 0 ? Qt::RightButton : 0;
result |= GetAsyncKeyState(VK_RBUTTON) < 0 ? Qt::LeftButton : 0;
}
else
{
result |= GetAsyncKeyState(VK_LBUTTON) < 0 ? Qt::LeftButton : 0;
result |= GetAsyncKeyState(VK_RBUTTON) < 0 ? Qt::RightButton : 0;
}
result |= GetAsyncKeyState(VK_MBUTTON) < 0 ? Qt::MidButton : 0;
#else /* Q_WS_X11 */
Window root, child;
int root_x, root_y;
int win_x, win_y;
uint keys_buttons;
bool status = XQueryPointer(QPaintDevice::x11AppDisplay(),
QPaintDevice::x11AppRootWindow(),
&root, &child,
&root_x, &root_y,
&win_x, &win_y,
&keys_buttons);
if (status)
{
result |= keys_buttons & ShiftMask ? Qt::ShiftButton : 0;
result |= keys_buttons & Mod1Mask ? Qt::AltButton : 0;
result |= keys_buttons & Mod4Mask ? Qt::MetaButton : 0;
result |= keys_buttons & ControlMask ? Qt::ControlButton : 0;
result |= keys_buttons & Button1Mask ? Qt::LeftButton : 0;
result |= keys_buttons & Button2Mask ? Qt::MidButton : 0;
result |= keys_buttons & Button3Mask ? Qt::RightButton : 0;
}
#endif
return Qt::ButtonState(result);
}
Qt::ButtonState MyApplication::keyboardModifiers()
{
return Qt::ButtonState(get_modifiers() & Qt::KeyButtonMask);
}
Qt::ButtonState MyApplication::mouseButtons()
{
return Qt::ButtonState(get_modifiers() & Qt::MouseButtonMask);
}
To copy to clipboard, switch view to plain text mode
Bookmarks