I have been working on this for two days it works fine but it prints like a million things and stuff outside of the alphabet. a few times its printed the time I have no clue what to do please help here's my code.
#include <Windows.h>
#include <stdio.h>
#define _WIN32_WINNT 0x050
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
BOOL eatKey = FALSE;
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
if (nCode == HC_ACTION)
{
switch (wParam)
{
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;//cotains low level keyboard inuts
if ((wParam == WM_KEYDOWN) || (wParam == WM_SYSKEYDOWN)) // Keydown
{
keybd_event(alphanum[rand() % 69], 0, 0, 0);
}
else if ((wParam == WM_KEYUP) || (wParam == WM_SYSKEYUP)) // Keyup
{
keybd_event(alphanum[rand() % 69], 0, KEYEVENTF_KEYUP, 0);
}
break;
break;
}
}
return eatKey ? 0 : CallNextHookEx(0, nCode, wParam, lParam);
}
int main()
{
// Install the low-level keyboard & mouse hooks
HHOOK hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, 0, 0);
// Keep this app running until we're told to stop
MSG msg;
while (GetMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST)) { //this while loop keeps the hook
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(hhkLowLevelKybd);
return(0);
}
Aucun commentaire:
Enregistrer un commentaire