Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyboard hook

Status
Not open for further replies.

dominochmiel

Programmer
Jan 28, 2003
40
PL
I wrote a program using hook(it doesn't matter is this keyboard hook or message hook or else) which works perfectly until I don't want to capture all messeges or key events in system. It works only when identifier of the thread with which the hook procedure is to be associated is HInstance. But then hook intercept only messeges in my app not in system. Below I'm enclosing app code(this working). Maybe somone can correct me and show what is incorrect.


void *hook;

LRESULT HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode==HC_ACTION)
ShowMessage(char(wParam));
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
hook=SetWindowsHookEx(WH_KEYBOARD_LL ,HOOKPROC(HookProc),HInstance,NULL);
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
UnhookWindowsHookEx(hook);
}

Thanks for help.
 
Ups I forgot. My problems starts when I change HInstance in SetWindowsHookEx function to NULL to intercept all messages. Please help!!!
 
I don't quite understand. Do you want to be able to hook every message in the system? Kind of like Winsight? Or am I reading this wrong?

Chris
 
Yes you read it good. I solved this problem. HookProc function should be placed inside dll library and then it works perfektly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top