0

When ever i run this program my computer seems to freeze up and is unable to do anything. I think this is because i am for some reason always calling the keyboard helper function? could it be something to do with the pause that i have at the bottom of the program or is it something more. all that is contained inside the pause header and function is a getchar()

#include "pause.h"
#include <iostream>
#define null NULL
#include <Windows.h>
#pragma comment(lib,"user32.lib")


using namespace std;
HHOOK hHook=null;
char word[]="hello"; 

LRESULT CALLBACK KeyboardHelper(int nCode, WPARAM wParam,LPARAM lParam)
{
    return CallNextHookEx(hHook,nCode,wParam,lParam);
}

int main(void)
{

    hHook=SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardHelper,null,0);
    if(hHook==null)
    {
        cout<< "Hook failed"<<endl;
    }else 
    {
        cout<< "Worked"<<endl;
    }
    pause();
}
Lpc_dark
  • 2,834
  • 7
  • 32
  • 49
  • To hook all applications on the desktop of a 64-bit Windows installation, install a 32-bit global hook and a 64-bit global hook, each from appropriate processes, `and be sure to keep pumping messages in the hooking application to avoid blocking normal functioning` – joy Apr 21 '13 at 18:55
  • Before terminating, an application must call the UnhookWindowsHookEx function to free system resources associated with the hook. – joy Apr 21 '13 at 18:56
  • i have added UnhookWindowsHookEx(hHook); but i still get the freezing and this is a 64-bit operating system but didn't really understand what @neagoebab was saying to do? – Lpc_dark Apr 21 '13 at 19:11
  • Examples [here](https://www.google.ro/search?q=site%3Acodeproject.com+windows+hooks&rlz=1C1CHMO_enRO468RO469&aq=f&oq=site&aqs=chrome.0.59j57j0l2j62l2.2190j0&sourceid=chrome&ie=UTF-8#q=site:codeproject.com+windows+hooks&rlz=1C1CHMO_enRO468RO469&ei=6cp0Ue_CNoXn4QSJhYHYBg&start=0&sa=N&bav=on.2,or.r_qf.&bvm=bv.45512109,d.bGE&fp=1df98bcb435c9675&biw=1600&bih=775), sorry, I don't have time this morning to make a small sample application. – joy Apr 22 '13 at 05:31
  • hey thanks for taking the time. The link didn't really help tho was in vbscript I believe. I'm doing this in c++. – Lpc_dark Apr 22 '13 at 16:38

0 Answers0