From 2da5d28b2d0a3cd8a1bd4d39d4b291f305f6d19a Mon Sep 17 00:00:00 2001 From: Ruediger Gad Date: Thu, 12 Apr 2012 15:26:17 +0200 Subject: [PATCH] Refine button handling. Change key mappings. --- qml/QZeeControl/MainPage.qml | 18 ++++++++++++++++ xtstadapter.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++ xtstadapter.h | 26 +++++++++++++++++------ 3 files changed, 86 insertions(+), 6 deletions(-) diff --git a/qml/QZeeControl/MainPage.qml b/qml/QZeeControl/MainPage.qml index 3188ac7..58cf162 100644 --- a/qml/QZeeControl/MainPage.qml +++ b/qml/QZeeControl/MainPage.qml @@ -145,6 +145,8 @@ Page { BtConnector{ id: btConn + property int joystickThreshold: 50 + onConnected: { connectButton.enabled = false disconnectButton.enabled = true @@ -189,6 +191,22 @@ Page { xtstAdapter.sendKeyPress("d"); } } + + onXChanged: { + if(val > joystickThreshold){ + xtstAdapter.sendKeyPress("Right"); + }else if(val < -joystickThreshold){ + xtstAdapter.sendKeyPress("Left"); + } + } + + onYChanged: { + if(val > joystickThreshold){ + xtstAdapter.sendKeyPress("Down"); + }else if(val < -joystickThreshold){ + xtstAdapter.sendKeyPress("Up"); + } + } } XtstAdapter{ diff --git a/xtstadapter.cpp b/xtstadapter.cpp index 0bfe779..20f4e3c 100644 --- a/xtstadapter.cpp +++ b/xtstadapter.cpp @@ -1 +1,49 @@ +/* + * Copyright 2012 Ruediger Gad + * + * This file is part of QZeeControl. + * + * QZeeControl is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QZeeControl is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QZeeControl. If not, see . + */ + #include "xtstadapter.h" + +void XtstAdapter::sendKeyPress(QString key){ + int keyCode = XKeysymToKeycode(display, XStringToKeysym(key.toUtf8().constData())); + +// "Shift_L" on N9 equals keycode 50. +// qDebug("Shift_L is: %d", XKeysymToKeycode(display, XStringToKeysym("Shift_L"))); + + /* + * In case we want to send a single upper case character we press and release shift + * prior respectively after sending our actual key press. + */ + bool isUpperCaseChar = (key.length() == 1 && key.at(0).isUpper()); + if(isUpperCaseChar){ + XTestFakeKeyEvent(display, 50, true, 0); + } + + XTestFakeKeyEvent(display, keyCode, true, 0); + XTestFakeKeyEvent(display, keyCode, false, 0); + + /* + * In case we want to send a single upper case character we press and release shift + * prior respectively after sending our actual key press. + */ + if(isUpperCaseChar){ + XTestFakeKeyEvent(display, 50, false, 0); + } + + XFlush(display); +} diff --git a/xtstadapter.h b/xtstadapter.h index 6ed1d5d..ef3139e 100644 --- a/xtstadapter.h +++ b/xtstadapter.h @@ -1,3 +1,22 @@ +/* + * Copyright 2012 Ruediger Gad + * + * This file is part of QZeeControl. + * + * QZeeControl is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QZeeControl is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QZeeControl. If not, see . + */ + #ifndef XTSTADAPTER_H #define XTSTADAPTER_H @@ -18,12 +37,7 @@ public: signals: public slots: - void sendKeyPress(QString key){ - int keyCode = XKeysymToKeycode(display, XStringToKeysym(key.toLocal8Bit().constData())); - XTestFakeKeyEvent(display, keyCode, true, 0); - XTestFakeKeyEvent(display, keyCode, false, 0); - XFlush(display); - } + void sendKeyPress(QString key); private: Display *display; -- 1.7.9.5