فهرست منبع

renamed to 'toontown-stay-awake'

Fabian Peter Hammerle 8 سال پیش
والد
کامیت
186b56eab3
2فایلهای تغییر یافته به همراه18 افزوده شده و 11 حذف شده
  1. 5 5
      CMakeLists.txt
  2. 13 6
      main.cpp

+ 5 - 5
CMakeLists.txt

@@ -1,5 +1,5 @@
-cmake_minimum_required (VERSION 2.8.0)
-project (app)
+cmake_minimum_required(VERSION 2.8.0)
+project(toontown-stay-awake)
 
 
 file(GLOB SOURCES *.cpp)
 file(GLOB SOURCES *.cpp)
 
 
@@ -8,9 +8,9 @@ if(NOT XDO_LIB)
     message(FATAL_ERROR "libxdo not found")
     message(FATAL_ERROR "libxdo not found")
 endif()
 endif()
 
 
+add_definitions(-std=c++11)
 # add_definitions(-pthread)
 # add_definitions(-pthread)
-# add_definitions(-std=c++11)
 # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
 # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
 
 
-add_executable(app ${SOURCES})
-target_link_libraries(app "${XDO_LIB}")
+add_executable(toontown-stay-awake ${SOURCES})
+target_link_libraries(toontown-stay-awake "${XDO_LIB}")

+ 13 - 6
main.cpp

@@ -1,10 +1,12 @@
 #include <cstring>
 #include <cstring>
 #include <cassert>
 #include <cassert>
-#include <iostream>
+#include <thread>
+#include <chrono>
 extern "C" {
 extern "C" {
     #include <xdo.h>
     #include <xdo.h>
 }
 }
 
 
+const auto KEY_INTERVAL = std::chrono::seconds(64);
 const useconds_t KEY_DELAY = 12000; // microseconds
 const useconds_t KEY_DELAY = 12000; // microseconds
 
 
 void search_windows_by_name(const xdo_t* xdo, const char* name_regex, Window** windowlist_ret, unsigned int* nwindows_ret) {
 void search_windows_by_name(const xdo_t* xdo, const char* name_regex, Window** windowlist_ret, unsigned int* nwindows_ret) {
@@ -21,17 +23,22 @@ void search_toontown_windows(const xdo_t* xdo, Window** windowlist_ret, unsigned
     search_windows_by_name(xdo, "Toontown.*", windowlist_ret, nwindows_ret);
     search_windows_by_name(xdo, "Toontown.*", windowlist_ret, nwindows_ret);
 }
 }
 
 
-int main() {
-    xdo_t* xdo = xdo_new(NULL);
-    assert(xdo);
-
+void send_keysequence(const xdo_t* xdo) {
     Window* windows;
     Window* windows;
     unsigned int nwindows;
     unsigned int nwindows;
     search_toontown_windows(xdo, &windows, &nwindows);
     search_toontown_windows(xdo, &windows, &nwindows);
     for(unsigned int i=0; i<nwindows; i++) {
     for(unsigned int i=0; i<nwindows; i++) {
-        xdo_send_keysequence_window(xdo, windows[i], "Right", KEY_DELAY);
         xdo_send_keysequence_window(xdo, windows[i], "Left", KEY_DELAY);
         xdo_send_keysequence_window(xdo, windows[i], "Left", KEY_DELAY);
+        xdo_send_keysequence_window(xdo, windows[i], "Right", KEY_DELAY);
     }
     }
+}
 
 
+int main() {
+    xdo_t* xdo = xdo_new(NULL);
+    assert(xdo);
+    while(true) {
+        send_keysequence(xdo);
+        std::this_thread::sleep_for(KEY_INTERVAL);
+    }
     return 0;
     return 0;
 }
 }