11#include " XHook.h"
2- #include " xhook_engine.h"
32#include < errno.h>
43#include < fcntl.h>
54#include < stdio.h>
1413#include < QtCore>
1514using namespace Engine ;
1615
17- #include " xhook_engine.h"
18-
1916/* libUIOHook: Cross-platfrom userland keyboard and mouse hooking.
2017 * Copyright (C) 2006-2017 Alexander Barker. All Rights Received.
2118 * https://github.com/kwhat/libuiohook/
@@ -45,7 +42,7 @@ using namespace Engine;
4542#include < string.h>
4643#include < uiohook.h>
4744#include < wchar.h>
48- static int current_mode;
45+ static XHookMode current_mode;
4946
5047static Engine::Hook::HookState currentState;
5148static std::unique_ptr<QMutex> lock = std::make_unique<QMutex>();
@@ -84,15 +81,12 @@ bool logger_proc(unsigned int level, const char *format, ...) {
8481// thread.
8582void dispatch_proc (uiohook_event *const event) {
8683 QMutexLocker locker{lock.get ()};
87- printf (" \n dispatch_proc1\n " );
88- printf (" current mode:%d\n " , current_mode);
8984 switch (event->type ) {
9085 case EVENT_KEY_PRESSED:
9186 case EVENT_KEY_RELEASED:
9287 case EVENT_KEY_TYPED:
93- printf (" event->type:%d" , event->type );
94- if (current_mode == IOHOOK_KEYBOARD_MODE ||
95- current_mode == IOHOOK_KEYBOARD_AND_MOUSE_MODE) {
88+ if (current_mode == XHookMode::KEYBOARD ||
89+ current_mode == XHookMode::MOUSE_AND_KEYBOARD) {
9690 // printf("%d\n", IOHOOK_KEYBOARD_MODE);
9791 currentState = Engine::Hook::HookState::productive;
9892 }
@@ -103,18 +97,17 @@ void dispatch_proc(uiohook_event *const event) {
10397 case EVENT_MOUSE_MOVED:
10498 case EVENT_MOUSE_DRAGGED:
10599 case EVENT_MOUSE_WHEEL:
106- if (current_mode == IOHOOK_MOUSE_MODE ||
107- current_mode == IOHOOK_KEYBOARD_AND_MOUSE_MODE ) {
100+ if (current_mode == XHookMode::MOUSE ||
101+ current_mode == XHookMode::MOUSE_AND_KEYBOARD ) {
108102 currentState = Engine::Hook::HookState::productive;
109103 }
110104 break ;
111105 default :
112106 break ;
113107 }
114- printf (" dispatch_proc2\n " );
115108}
116109
117- int Engine::run_xhook_engine (int mode) {
110+ int Engine::run_xhook_engine (XHookMode mode) {
118111 // We need to disable buffering in order for this process to send the
119112 // "readyReadStandardOutput" signal to Tasker
120113 setbuf (stdout, NULL );
@@ -216,26 +209,6 @@ int Engine::run_xhook_engine(int mode) {
216209 */
217210XHook::XHook (Engine::XHookMode newXMode) {
218211 XMode = newXMode;
219- xChildHook.setParent (this );
220- // switch (XMode) {
221- // case XHookMode::MOUSE_AND_KEYBOARD:
222- // xChildHookArguments << IOHOOK_KEYBOARD_AND_MOUSE_MODE;
223- // break;
224- // case XHookMode::MOUSE:
225- // xChildHookArguments << IOHOOK_MOUSE_MODE;
226- // break;
227- // case XHookMode::KEYBOARD:
228- // xChildHookArguments << IOHOOK_KEYBOARD_MODE;
229- // break;
230- // }
231- connect (&xChildHook, &QProcess::readyReadStandardOutput, this ,
232- &XHook::update);
233- connect (&xChildHook, &QProcess::errorOccurred, this ,
234- [=](QProcess::ProcessError e) { qDebug () << " error code=" << e; });
235- connect (&xChildHook, &QProcess::readyReadStandardError, this , [=]() {
236- QByteArray errorData = this ->xChildHook .readAllStandardError ();
237- qDebug () << " Error on Xhook process:" << QString{errorData};
238- });
239212 currentState = state;
240213}
241214/* *
@@ -244,28 +217,16 @@ XHook::XHook(Engine::XHookMode newXMode) {
244217 * process.
245218 * @param newXMode The mode(mouse, keyboard or both) this instance will be on.
246219 */
247- XHook::XHook () {
248- XMode = XHookMode::MOUSE_AND_KEYBOARD;
249- xChildHook.setParent (this );
250- // xChildHookArguments << IOHOOK_KEYBOARD_AND_MOUSE_MODE;
251- connect (&xChildHook, &QProcess::readyReadStandardOutput, this ,
252- &XHook::update);
253- connect (&xChildHook, &QProcess::errorOccurred, this ,
254- [=](QProcess::ProcessError e) { qDebug () << " error code=" << e; });
255- connect (&xChildHook, &QProcess::readyReadStandardError, this , [=]() {
256- QByteArray errorData = this ->xChildHook .readAllStandardError ();
257- qDebug () << " Error on Xhook process:" << QString{errorData};
258- });
259- }
220+ XHook::XHook () { XMode = XHookMode::MOUSE_AND_KEYBOARD; }
260221/* *
261222 * @brief XHook::start
262223 */
263224void XHook::start () { startXHook (); }
264225
265226/* *
266- * @brief XHook::end kills the XListenerHook process .
227+ * @brief XHook::end kills the keyboard/mouse hook .
267228 */
268- void XHook::end () { xChildHook. kill (); }
229+ void XHook::end () { hook_stop (); }
269230
270231/* *
271232 * @brief XHook::pause Does nothing.
@@ -278,24 +239,7 @@ void XHook::pause() {}
278239 * It's essentially IPC.
279240 *
280241 */
281- void XHook::update () {
282- // current_mode = 12;
283- return ;
284- QByteArray Xdata = xChildHook.readAllStandardOutput ();
285- qDebug () << " update for Xhook..." ;
286- Xdata.chop (Xdata.length () - 1 );
287- QString iohookState{Xdata};
288- if (XMode == XHookMode::MOUSE_AND_KEYBOARD &&
289- iohookState == IOHOOK_KEYBOARD_AND_MOUSE_MODE) {
290- setState (HookState::productive);
291- } else if (XMode == XHookMode::MOUSE && iohookState == IOHOOK_MOUSE_MODE) {
292- setState (HookState::productive);
293- } else if (XMode == XHookMode::KEYBOARD &&
294- iohookState == IOHOOK_KEYBOARD_MODE) {
295- setState (HookState::productive);
296- } else {
297- }
298- }
242+ void XHook::update () { return ; }
299243
300244/* *
301245 * @brief XHook::startHook
@@ -311,20 +255,17 @@ void XHook::resetState() { setState(HookState::unproductive); }
311255 */
312256int XHook::startXHook () {
313257 setState (HookState::unproductive);
314- printf (" current val:%d\n " , current_mode);
315258
316- run_xhook_engine (IOHOOK_KEYBOARD_MODE );
259+ run_xhook_engine (XMode );
317260
318261 return 0 ;
319262}
320263void XHook::setState (HookState newState) {
321264 QMutexLocker locker{lock.get ()};
322- printf (" \n setState1\n " );
323265 currentState = newState;
324266 state = currentState;
325267
326268 Hook::setState (state);
327- printf (" setState2\n " );
328269}
329270/* *
330271 * @brief Engine::Engine::Hook::getState
0 commit comments