diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..9ead561c369e5495cd9f985d703f52ff0da8de5c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Keyboard/ diff --git a/Keyboard.pro b/Keyboard.pro index f054b9c68c8648c5165b2aac6ddd827b44195b13..3496bace7d6f3e713bfc8e0dd8a31418d400162d 100644 --- a/Keyboard.pro +++ b/Keyboard.pro @@ -18,14 +18,20 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ button.cpp \ main.cpp \ - keyboard.cpp + keyboard.cpp \ + util.cpp HEADERS += \ button.h \ key.h \ - keyboard.h + keyboard.h \ + util.h # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +PKGCONFIG += x11 +LIBS += -lXtst +CONFIG += link_pkgconfig diff --git a/Keyboard.pro.user b/Keyboard.pro.user new file mode 100644 index 0000000000000000000000000000000000000000..e06d545bb62d8b9036afb485ac60efd84b76fb44 --- /dev/null +++ b/Keyboard.pro.user @@ -0,0 +1,317 @@ + + + + + + EnvironmentId + {6a27d286-b052-49fe-b200-12733d5ea90e} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + true + true + true + true + + + 0 + true + + true + Builtin.Questionable + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 5.15.2 GCC 64bit + Desktop Qt 5.15.2 GCC 64bit + qt.qt5.5152.gcc_64_kit + 0 + 0 + 0 + + 0 + /home/linton/桌面/build-Keyboard-Desktop_Qt_5_15_2_GCC_64bit-Debug + /home/linton/桌面/build-Keyboard-Desktop_Qt_5_15_2_GCC_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 0 + + + /home/linton/桌面/build-Keyboard-Desktop_Qt_5_15_2_GCC_64bit-Release + /home/linton/桌面/build-Keyboard-Desktop_Qt_5_15_2_GCC_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + + 0 + /home/linton/桌面/build-Keyboard-Desktop_Qt_5_15_2_GCC_64bit-Profile + /home/linton/桌面/build-Keyboard-Desktop_Qt_5_15_2_GCC_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/keyboard.cpp b/keyboard.cpp index 64716e968d0e43e0434a6e5dc4cc0273bbd74436..e0bf2a781b726a2cc53edcb387fb96148386da31 100644 --- a/keyboard.cpp +++ b/keyboard.cpp @@ -286,5 +286,5 @@ void Keyboard::clickedSlot(Key key) } void Keyboard::send2Screen(Key key){ - //将key转换为对应的字符并输出到设备 + util.inputstr("as"); } diff --git a/keyboard.h b/keyboard.h index 29fcafe55aca536bc37f83f0d4562475ed5940fe..7b07d11417517801d6e7e0fe5c2dc6e31ce06429 100644 --- a/keyboard.h +++ b/keyboard.h @@ -5,11 +5,13 @@ #include #include #include "key.h" +#include "util.h" class Keyboard : public QWidget { Q_OBJECT private: + Util util; QString context; QLabel *q; QWidget *EngKeyboard,*NumKeyboard; diff --git a/util.cpp b/util.cpp new file mode 100644 index 0000000000000000000000000000000000000000..04895b8705b230910801f8041fc7a4dbcd445408 --- /dev/null +++ b/util.cpp @@ -0,0 +1,53 @@ +#include "util.h" + +Util::Util() +{ + timer=new QTimer; + connect(timer,SIGNAL(timeout()),this,SLOT(resetclipboard())); +} + +void Util::resetclipboard(){ + if(timer->isActive()){ + timer->stop(); + } + QClipboard* clipboard=QApplication::clipboard(); + clipboard->setText(origin); +} + +void Util::inputkey(Key key){ + ; +} + +void Util::inputstr(QString str){ + Display *disp = XOpenDisplay(NULL); + if (disp == NULL){ + return; + } + + + QClipboard* clipboard=QApplication::clipboard(); + + origin=clipboard->text(); + clipboard->setText(str); + + XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Control_L), true,0); + XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_V), true,0); + XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_V), false,0); + XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Control_L), false,0); + + XCloseDisplay(disp); + + timer->start(50); +} + +void Util::delchar(){ + Display *disp = XOpenDisplay(NULL); + if (disp == NULL){ + return; + } + + XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_BackSpace), true,0); + XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_BackSpace), false,0); + + XCloseDisplay(disp); +} diff --git a/util.h b/util.h new file mode 100644 index 0000000000000000000000000000000000000000..37496cebbbf809774f81fe9bb85a35e99f8f2318 --- /dev/null +++ b/util.h @@ -0,0 +1,42 @@ +#ifndef UTIL_H +#define UTIL_H + +#include +#include +#include +#include "qdebug.h" +#include +#include +#include +#include +#include +#include "key.h" + +#undef Bool +#undef CursorShape +#undef Expose +#undef KeyPress +#undef KeyRelease +#undef FocusIn +#undef FocusOut +#undef FontChange +#undef None +#undef Status +#undef Unsorted + +class Util :public QObject +{ + Q_OBJECT +private: + QTimer* timer; + QString origin; +public: + Util(); + void inputkey(Key key); + void delchar(); + void inputstr(QString str); +public slots: + void resetclipboard(); +}; + +#endif // UTIL_H