here is what I've done so far trying to learn to deal with hooks, buttons and messages on windows:
in main.cpp
//Create a thread for keyboard:
HANDLE hScreenThread2;
DWORD idScreenThread2;
hScreenThread2 = CreateThread(0, 0, (LPTHREAD_START_ROUTINE) KeyLogger, 0, 0, &idScreenThread2);
if(hScreenThread2) {
WaitForSingleObject(hScreenThread2, INFINITE);
TerminateThread(hScreenThread2, 0);
CloseHandle(hScreenThread2);
}
in keylogger.cpp
DLLEXPORT DWORD WINAPI KeyLogger ( LPVOID lpParamenter )
{
//armazena a mensagem do windows
HINSTANCE hExe = GetModuleHandle(NULL); //?
//cria o hook
hHook1 = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC) KeyBoardHook, hExe, 0);
//loop de mensagens
MessageLoop();
//destrói o hook
UnhookWindowsHookEx(hHook1);
return 0;
}
The message loop
VOID MessageLoop()
{
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
and finally the source of my headache:
LRESULT CALLBACK KeyBoardHook( int nCode, WPARAM wParam, LPARAM lParam )
{
if((nCode == HC_ACTION) && (wParam == WM_KEYDOWN))
{
wchar_t c;
switch (wParam)
{
case WM_CHAR:
c = (wchar_t)wParam;
break;
default:
break;
}
}
return CallNextHookEx(hHook1,nCode,wParam,lParam);
}
In short: I can not capture keystrokes and much less the keys that must be combined to form accented letters on my keyboard for example I have to press the acute accent (') drop and press the letter (e) for to have the letter "é". My keyboard is ABNT2 Brazilian Portuguese. Any idea where to start because I've tried using GetAsyncKeyState () but as said before that I have a letter "é" I have to first press the key ('), release it and then press down another key and I dont know how to make for capture two events separate. I've tried GetKeyState (0) along with GetKeyboardState (kb) (kb is a BYTE buffer with space of 256).
Thanks for any help or ideia.