1 /***************************************************************************
2 * Copyright (C) 2003 by Sébastien Laoût *
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 *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <kapplication.h> // it define Q_WS_X11
25 /* This file contain modified code from klistbox.cpp
28 // ShiftMask, ControlMask and Mod1Mask are defined in <X11/X.h>
29 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
30 #include <X11/Xlib.h> // schroder
34 void Keyboard::pressedKeys(bool &shiftPressed
, bool &controlPressed
)
36 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
39 int root_x
, root_y
, win_x
, win_y
;
41 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root
, &child
,
42 &root_x
, &root_y
, &win_x
, &win_y
, &keybstate
);
44 shiftPressed
= keybstate
& ShiftMask
;
45 controlPressed
= keybstate
& ControlMask
;
49 /** Same code as pressedKeys(...) but for shift key only
51 bool Keyboard::shiftPressed()
53 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
56 int root_x
, root_y
, win_x
, win_y
;
58 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root
, &child
,
59 &root_x
, &root_y
, &win_x
, &win_y
, &keybstate
);
61 return (keybstate
& ShiftMask
) != 0;
67 /** Same code as pressedKeys(...) but for control key only
69 bool Keyboard::controlPressed()
71 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
74 int root_x
, root_y
, win_x
, win_y
;
76 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root
, &child
,
77 &root_x
, &root_y
, &win_x
, &win_y
, &keybstate
);
79 return (keybstate
& ControlMask
) != 0;
85 /** Return if Alt key is pressed
87 bool Keyboard::altPressed()
89 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
92 int root_x
, root_y
, win_x
, win_y
;
94 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root
, &child
,
95 &root_x
, &root_y
, &win_x
, &win_y
, &keybstate
);
97 return (keybstate
& Mod1Mask
) != 0;
104 * What does KDE 3.1 and later:
105 * FIXME: Use this function in KDE 4
106 * (I wasn't knowing it by creating this class)
109 * Returns the currently pressed keyboard modifiers (e.g. shift, control, etc.)
110 * Usually you simply want to test for those in key events, in which case
111 * QKeyEvent::state() does the job (or QKeyEvent::key() to
112 * notice when a modifier is pressed alone).
113 * But it can be useful to query for the status of the modifiers at another moment
114 * (e.g. some KDE apps do that upon a drop event).
115 * @return the keyboard modifiers
118 uint KApplication::keyboardModifiers()
122 int root_x, root_y, win_x, win_y;
124 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root, &child,
125 &root_x, &root_y, &win_x, &win_y, &keybstate );
126 return keybstate & 0x00ff;