Sometimes its the little things..
[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     sendKey(key, true);
24     sendKey(key, false);
25 //    int keyCode = XKeysymToKeycode(display, XStringToKeysym(key.toUtf8().constData()));
26
27 ////        "Shift_L" on N9 equals keycode 50.
28 ////        qDebug("Shift_L is: %d", XKeysymToKeycode(display, XStringToKeysym("Shift_L")));
29
30 //    /*
31 //     * In case we want to send a single upper case character we press and release shift
32 //     * prior respectively after sending our actual key press.
33 //     */
34 //    bool isUpperCaseChar = (key.length() == 1 && key.at(0).isUpper());
35 //    if(isUpperCaseChar){
36 //        XTestFakeKeyEvent(display, 50, true, 0);
37 //    }
38
39 //    XTestFakeKeyEvent(display, keyCode, true, 0);
40 //    XTestFakeKeyEvent(display, keyCode, false, 0);
41
42 //    /*
43 //     * In case we want to send a single upper case character we press and release shift
44 //     * prior respectively after sending our actual key press.
45 //     */
46 //    if(isUpperCaseChar){
47 //        XTestFakeKeyEvent(display, 50, false, 0);
48 //    }
49
50 //    XFlush(display);
51 }
52
53 void XtstAdapter::sendKey(QString key, bool down){
54     int keyCode = XKeysymToKeycode(display, XStringToKeysym(key.toUtf8().constData()));
55
56 //        "Shift_L" on N9 equals keycode 50.
57 //        qDebug("Shift_L is: %d", XKeysymToKeycode(display, XStringToKeysym("Shift_L")));
58
59     /*
60      * In case we want to send a single upper case character we press and release shift
61      * prior respectively after sending our actual key press.
62      */
63     bool isUpperCaseChar = (key.length() == 1 && key.at(0).isUpper());
64     if(isUpperCaseChar){
65         XTestFakeKeyEvent(display, 50, true, 0);
66     }
67
68     XTestFakeKeyEvent(display, keyCode, down, 0);
69
70     /*
71      * In case we want to send a single upper case character we press and release shift
72      * prior respectively after sending our actual key press.
73      */
74     if(isUpperCaseChar){
75         XTestFakeKeyEvent(display, 50, false, 0);
76     }
77
78     XFlush(display);
79 }