1 /*****************************************************************************
2 * keyboard.cpp - QStarDict, a StarDict clone written with using Qt *
3 * Copyright (C) 2007 Alexander Rodin *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License along *
16 * with this program; if not, write to the Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18 *****************************************************************************/
25 #include <X11/XKBlib.h>
30 const unsigned mAlt = 0010;
31 const unsigned mCtrl = 0004;
32 const unsigned mShift = 0001;
33 const unsigned mWin = 0100;
39 Qt::KeyboardModifiers Keyboard::activeModifiers()
42 Qt::KeyboardModifiers result;
44 XkbGetState(QX11Info::display(), XkbUseCoreKbd, &state);
45 if (state.base_mods & mAlt)
46 result |= Qt::AltModifier;
47 if (state.base_mods & mCtrl)
48 result |= Qt::ControlModifier;
49 if (state.base_mods & mShift)
50 result |= Qt::ShiftModifier;
51 if (state.base_mods & mWin)
52 result |= Qt::MetaModifier;
59 #elif defined(Q_WS_WIN) // Q_WS_X11
67 Qt::KeyboardModifiers Keyboard::activeModifiers()
69 Qt::KeyboardModifiers result;
71 if (GetAsyncKeyState(VK_MENU) & 0x8000)
72 result |= Qt::AltModifier;
73 if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
74 result |= Qt::ControlModifier;
75 if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
76 result |= Qt::ShiftModifier;
77 if ((GetAsyncKeyState(VK_LWIN) & 0x8000) || (GetAsyncKeyState(VK_RWIN) & 0x8000))
78 result |= Qt::MetaModifier;
85 #elif defined(Q_WS_MAC) // Q_WS_WIN
86 #include <QApplication>
91 Qt::KeyboardModifiers Keyboard::activeModifiers()
93 return QApplication::keyboardModifiers();
99 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc