c++ - WIN32 SendInput only working for some programs - code included -


i started working on small bot project fun way dive win32 api (among other things). in particular, sendinput behaving expected in instances.

as proof of concept set loop send 's' key make sure things working. if set window want activate notepad, text appears fine. if set window ikaruga, window pops menu doesn't change (game uses wasd menu navigation, should continually go down).

i have read in multiple places games have (not reliable) options blocking external input. check if case, found project built key sender. particular project used here enter link description here . code sent 's' keys ikaruga expected.

he included source code. i've spent fair bit of time reading on it. while lot of functions using have been superseded, overall code flow similar.

hopefully, can provide me guidance on i'm doing wrong.

#ifdef _msc_ver #define _crt_secure_no_warnings #define _crt_nonstdc_no_deprecate #endif  #define winver 0x0500 #include <windows.h> #include <stdio.h> #include <tchar.h>  void appactivate(lpctstr windowtitle){      // first window on desktop     hwnd firstwindow = findwindowex(null, null, null, null);     hwnd window = firstwindow;     tchar windowtext[max_path];      // guard against search word matching current console title     tchar consoletitle[max_path];     getconsoletitle(consoletitle, max_path);      while (1){         // check window title match         getwindowtext(window, windowtext, max_path);         if (strstr(windowtext, windowtitle) != null && strcmp(windowtext, consoletitle) != 0){             break;         }          // next window         window = findwindowex(null, window, null, null);         if (window == null || window == firstwindow){             fprintf(stderr, "window not found\n");         }     }     fprintf(stderr, "window found: %s\n", windowtext);      // bring specified window focus     allowsetforegroundwindow(true);     showwindow(window, sw_restore);     setforegroundwindow(window);     setfocus(window); }  int main(int argc, char* argv[]){     appactivate("ikaruga");      sleep(2000);      // create generic keyboard event structure     input ip;     ip.type = input_keyboard;     ip.ki.wvk = 0; // scan code 's'     ip.ki.time = 0;     ip.ki.dwextrainfo = 0;       while (1){         // press "s" key         ip.ki.wscan = 0x1f; // 0x1f 's'         ip.ki.dwflags = 0; // 0 key press         sendinput(1, &ip, sizeof(input));          // release "s" key         ip.ki.wscan = 0x1f;         ip.ki.dwflags = keyeventf_keyup;         sendinput(1, &ip, sizeof(input));          char msgbuf[200];         sprintf(msgbuf, "pressing s\n");         outputdebugstring(msgbuf);          sleep(2000);     }      return 0; } 

edit: forgot mention i've tried setting code on both wvk/wscan , 's' vs 0x53.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -