First prototype for sending key events.
authorRuediger Gad <rgad@fb2.fh-frankfurt.de>
Thu, 12 Apr 2012 11:41:54 +0000 (13:41 +0200)
committerRuediger Gad <rgad@fb2.fh-frankfurt.de>
Thu, 12 Apr 2012 11:41:54 +0000 (13:41 +0200)
main.cpp
qml/QZeeControl/MainPage.qml
xtstadapter.h

index 9a89289..7296149 100644 (file)
--- a/main.cpp
+++ b/main.cpp
 #include <QtDeclarative>
 #include "qmlapplicationviewer.h"
 #include "btconnector.h"
+#include "xtstadapter.h"
 
 Q_DECL_EXPORT int main(int argc, char *argv[])
 {
     QScopedPointer<QApplication> app(createApplication(argc, argv));
 
     qmlRegisterType<BtConnector>("qzeecontrol", 1, 0, "BtConnector");
+    qmlRegisterType<XtstAdapter>("qzeecontrol", 1, 0, "XtstAdapter");
 
     QmlApplicationViewer viewer;
     viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
index c03ab78..ef75026 100644 (file)
@@ -169,9 +169,33 @@ Page {
             labelD.color = d ? "red" : "blue"
         }
 
-        onAChanged: console.log("A changed to: " + val)
-        onBChanged: console.log("B changed to: " + val)
-        onCChanged: console.log("C changed to: " + val)
-        onDChanged: console.log("D changed to: " + val)
+        onAChanged: {
+            console.log("A changed to: " + val)
+            if(val){
+                xtstAdapter.sendKeyPress("a");
+            }
+        }
+        onBChanged: {
+            console.log("B changed to: " + val)
+            if(val){
+                xtstAdapter.sendKeyPress("b");
+            }
+        }
+        onCChanged: {
+            console.log("C changed to: " + val)
+            if(val){
+                xtstAdapter.sendKeyPress("c");
+            }
+        }
+        onDChanged: {
+            console.log("D changed to: " + val)
+            if(val){
+                xtstAdapter.sendKeyPress("d");
+            }
+        }
+    }
+
+    XtstAdapter{
+        id: xtstAdapter
     }
 }
index 65c108b..6ed1d5d 100644 (file)
@@ -18,6 +18,12 @@ 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);
+    }
 
 private:
     Display *display;