1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include <Windows.h>
#include <string>
#include <cstdlib>
#include <time.h>
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define SHIFT 0x10
#define CTRL 0x11
#define ALT 0x12
#define ENTER 0x0D
#define BACKSPACE 0x08
#define NOMOD 0
class kbd
{
BYTE * key_buffer;
public:
void write(std::string s, bool enter, bool human/*type in a human-like manner at a moderate typing speed*/)
{
srand(time(NULL));
int buffer_size = s.length();
key_buffer = new BYTE[buffer_size];
for(int i = 0; i < buffer_size; i++)
{
key_buffer[i] = s[i];
}
for(int i = 0; i < buffer_size; i++)
{
if(isalpha(key_buffer[i]))
{
if(isupper(key_buffer[i]))
{
press(key_buffer[i], human, SHIFT);
}
else
{
press(toupper(key_buffer[i]), human, NOMOD);
}
}
else
{
short scan = VkKeyScan(key_buffer[i]);
key_buffer[i] = LOBYTE(scan);
switch(HIBYTE(scan))
{
case 1:
press(key_buffer[i], human, SHIFT);
break;
case 2:
press(key_buffer[i], human, CTRL);
break;
case 4:
press(key_buffer[i], human, ALT);
break;
default:
press(key_buffer[i], human, NOMOD);
break;
}
}
}
if(enter)
{
press(ENTER, human, NOMOD);
}
delete[] key_buffer;
return;
}
void press(BYTE key, bool human, BYTE modKey)
{
if(human){Sleep(rand() % 40 + 10);} // approximate time taking for a user to move their finger from one key to the next.
if(modKey)
{
if(human)
{
keybd_event(modKey, NULL, NULL, NULL); //modifier key down
Sleep(rand() % 55 + 15);
keybd_event(key, NULL, NULL, NULL); //key down
Sleep(rand() % 15 + 5);
keybd_event(key, NULL, KEYEVENTF_KEYUP, NULL); //key up
Sleep(rand() % 55 + 15);
keybd_event(modKey, NULL, KEYEVENTF_KEYUP, NULL); //modifier key up
}
else
{
keybd_event(modKey, NULL, NULL, NULL); //modifier key down
keybd_event(key, NULL, NULL, NULL); //key down
keybd_event(key, NULL, KEYEVENTF_KEYUP, NULL); //key up
keybd_event(modKey, NULL, KEYEVENTF_KEYUP, NULL); //modifier key up
}
return;
}
else
{
if(human)
{
keybd_event(key, NULL, NULL, NULL);
Sleep(rand() % 15 + 5);
keybd_event(key, NULL, KEYEVENTF_KEYUP, NULL);
}
else
{
keybd_event(key, NULL, NULL, NULL);
keybd_event(key, NULL, KEYEVENTF_KEYUP, NULL);
}
return;
}
}
};
|