• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kremotecontrol

  • sources
  • kde-4.12
  • kdeutils
  • kremotecontrol
  • libkremotecontrol
keypressactionexecutor.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Michael Zanetti <mzanetti@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18 */
19 
20 #include "keypressactionexecutor.h"
21 #include "keypressaction.h"
22 
23 #include <KDebug>
24 #include <KWindowSystem>
25 
26 #include <netwm_def.h>
27 
28 #include <QtGui/QX11Info>
29 
30 #include <X11/keysym.h>
31 #include <X11/extensions/XTest.h>
32 
33 
34 void KeypressActionExecutor::execute(Action* action) {
35  KeypressAction *keypressAction = dynamic_cast<KeypressAction*>(action);
36  if(keypressAction){
37  foreach(const QKeySequence &key, keypressAction->keySequenceList()) {
38  kDebug() << "executing keypressaction:" << key;
39  executeKeypress(key);
40  }
41  } else {
42  kDebug() << "KeypressActionExecutor: action does not appear to be a KeypressAction";
43  }
44 }
45 
46 bool KeypressActionExecutor::executeKeypress(const QKeySequence &key)
47 {
48 
49  QList<KeyCode> modList = extractMods(key);
50 
51  bool ret = true;
52  foreach(KeyCode modcode, modList) {
53  kDebug() << "pressing modifier:" << modcode;
54  ret = ret && XTestFakeKeyEvent(QX11Info::display(), modcode, true, 0);
55  }
56 
57  int keySym;
58  KKeyServer::keyQtToSymX(key[0], &keySym);
59  kDebug() << "keysym" << keySym;
60  KeyCode keycode = XKeysymToKeycode(QX11Info::display(), keySym);
61 
62  kDebug() << "pressing key:" << keycode;
63  ret = ret && XTestFakeKeyEvent(QX11Info::display(), keycode, true, 0);
64  kDebug() << "releasing key:" << keycode;
65  ret = ret && XTestFakeKeyEvent(QX11Info::display(), keycode, false, 0);
66 
67 
68  foreach(KeyCode modcode, modList) {
69  kDebug() << "releasing modifier:" << modcode;
70  ret = ret && XTestFakeKeyEvent(QX11Info::display(), modcode, false, 0);
71  }
72 
73  // Qt's autorepeat compression is broken and can create "aab" from "aba"
74  // XSync() should create delay longer than Qt's max autorepeat interval
75  XSync( QX11Info::display(), False );
76  return ret;
77 }
78 
79 QList<KeyCode> KeypressActionExecutor::extractMods(const QKeySequence &keySequence)
80 {
81  QList<KeyCode> ret;
82 
83  if(keySequence.toString(QKeySequence::PortableText).contains("Shift+")) {
84  kDebug() << "sequence matches Shift!";
85  ret.append(XKeysymToKeycode(QX11Info::display(), XK_Shift_L));
86  }
87  if(keySequence.toString(QKeySequence::PortableText).contains("Alt+")) {
88  kDebug() << "sequence matches Alt!";
89  ret.append(XKeysymToKeycode(QX11Info::display(), XK_Alt_L));
90  }
91  if(keySequence.toString(QKeySequence::PortableText).contains("Ctrl+")) {
92  kDebug() << "sequence matches Ctrl!";
93  ret.append(XKeysymToKeycode(QX11Info::display(), XK_Control_L));
94  }
95  if(keySequence.toString(QKeySequence::PortableText).contains("Meta+")) {
96  kDebug() << "sequence matches Meta!";
97  ret.append(XKeysymToKeycode(QX11Info::display(), XK_Super_L));
98  }
99  return ret;
100 
101 }
102 
103 
KeypressActionExecutor::execute
virtual void execute(Action *action)
Definition: keypressactionexecutor.cpp:34
keypressactionexecutor.h
KeypressAction
Definition: keypressaction.h:27
keypressaction.h
Action
Definition: action.h:30
KeypressAction::keySequenceList
QList< QKeySequence > keySequenceList() const
Definition: keypressaction.cpp:76
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kremotecontrol

Skip menu "kremotecontrol"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal