Reputation: 31
I'm trying to write a little program (in C), which writes every pressed Key I'm pressing into a .txt-file (and yes, it's a keylogger).
But I don't want to use the stdio, because I'm using FreeConsole();
.
#include <stdio.h>
#include <windows.h>
int main()
{
char c;
int i = 0;
FILE *datei;
datei = fopen("test.txt","w+");
if (datei == NULL) exit(1);
FreeConsole();
while(1)
{
c = ??? ; //get KeyCode of pressed key
fprintf(datei, "%c",c);
if (c == 27)
{
break;
}
printf("%c",c);
}
fclose(datei);
return(0);
}
Hope I made it clear (hope)
Thanks! :)
Upvotes: 0
Views: 468
Reputation: 19266
You can't do that with only the standard library. The I/O functions that don't specify an explicit FILE*
found in the standard library get their data from the standard input (stdin
).
Thus, the standard input does not necessarily have to be attached to a terminal, from which you could retrieve actual keystrokes. You have to look into your operating system's documentation and APIs for that.
Upvotes: 3