Refine button handling. Change key mappings.
[qzeecontrol] / xtstadapter.cpp
1 /*
2  *  Copyright 2012 Ruediger Gad
3  *
4  *  This file is part of QZeeControl.
5  *
6  *  QZeeControl is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  QZeeControl is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with QZeeControl.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "xtstadapter.h"
21
22 void XtstAdapter::sendKeyPress(QString key){
23     int keyCode = XKeysymToKeycode(display, XStringToKeysym(key.toUtf8().constData()));
24
25 //        "Shift_L" on N9 equals keycode 50.
26 //        qDebug("Shift_L is: %d", XKeysymToKeycode(display, XStringToKeysym("Shift_L")));
27
28     /*
29      * In case we want to send a single upper case character we press and release shift
30      * prior respectively after sending our actual key press.
31      */
32     bool isUpperCaseChar = (key.length() == 1 && key.at(0).isUpper());
33     if(isUpperCaseChar){
34         XTestFakeKeyEvent(display, 50, true, 0);
35     }
36
37     XTestFakeKeyEvent(display, keyCode, true, 0);
38     XTestFakeKeyEvent(display, keyCode, false, 0);
39
40     /*
41      * In case we want to send a single upper case character we press and release shift
42      * prior respectively after sending our actual key press.
43      */
44     if(isUpperCaseChar){
45         XTestFakeKeyEvent(display, 50, false, 0);
46     }
47
48     XFlush(display);
49 }