1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include <cstring>
- #include <cassert>
- #include <thread>
- #include <chrono>
- extern "C" {
- #include <xdo.h>
- }
- const auto KEY_INTERVAL = std::chrono::seconds(64);
- 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) {
- xdo_search_t search;
- memset(&search, 0, sizeof(xdo_search_t));
- search.max_depth = -1;
- search.require = xdo_search::SEARCH_ALL;
- search.searchmask |= SEARCH_NAME;
- search.winname = name_regex;
- xdo_search_windows(xdo, &search, windowlist_ret, nwindows_ret);
- }
- void search_toontown_windows(const xdo_t* xdo, Window** windowlist_ret, unsigned int* nwindows_ret) {
- search_windows_by_name(xdo, "Toontown.*", windowlist_ret, nwindows_ret);
- }
- void send_keysequence(const xdo_t* xdo) {
- Window* windows;
- unsigned int nwindows;
- search_toontown_windows(xdo, &windows, &nwindows);
- for(unsigned int i=0; i<nwindows; i++) {
- 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;
- }
|