Refine button handling. Change key mappings.
authorRuediger Gad <rgad@fb2.fh-frankfurt.de>
Thu, 12 Apr 2012 13:26:17 +0000 (15:26 +0200)
committerRuediger Gad <rgad@fb2.fh-frankfurt.de>
Thu, 12 Apr 2012 13:26:17 +0000 (15:26 +0200)
qml/QZeeControl/MainPage.qml
xtstadapter.cpp
xtstadapter.h

index 3188ac7..58cf162 100644 (file)
@@ -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{
index 0bfe779..20f4e3c 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
 #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);
+}
index 6ed1d5d..ef3139e 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
 #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;