I read Iczelion's tutorial 24, and also did a small program to catch all keyboard messages. My program is supposed to catch all keyboard messages without passing them to the System. For example, in Notepad, you cannot input any characters when my program starts hooking all keyboard messages. Now my problem is: I can still input characters in to Notepad! My hook procedure is :

KeyboardProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD 
    invoke CallNextHookEx,hHook,nCode,wParam,lParam 
    invoke PostMessage,hWnd,WM_KEYBOARDHOOK,wParam,0 
    xor eax,eax 
KeyboardProc endp 
where WM_KEYBOARDHOOK is user-defined message. When my main window receives this WM_KEYBOARDHOOK, I simply MessageBox the "wParam" passed along with WM_KEYBOARDHOOK. What's wrong with my code? I cannot figure it out. Please help! This message was edited by Hiroshimator, on 3/6/2001 9:08:14 AM
Posted on 2001-03-02 11:53:00 by zhanghz
Up. Help please.
Posted on 2001-03-06 08:39:00 by zhanghz
I'm not absolutely sure, but I think this will only trap keys going to your app. bitRAKE.
Posted on 2001-03-06 15:34:00 by bitRAKE
hm, you CAN do system wide hooks but the callback must resist in a dll. but you want to catch them before they are transmited to some app ... i don't know if this is possible, for now i thought that i can only catch msg's that are fully accepted by some app. an app calls GetMessage or PeekMessage and AFTER that your hook is started ... maybe you can do something with CallNextHookEx... bye.
Posted on 2001-03-07 06:02:00 by drcmda
bitRAKE, I can trap keyboard messages after I start hooking in my application and even when my application is inactive. As I said, I open the notepad and type, the hook will get the keyboard message and pops up the messagebox. The problem is the characters I type still go in to the notepad. drcmda, My hook procedure is in dll. And I tried to comment the "invoke CallNextHookEx" also, but it didn't work. The mousehook is quite simple in the tutorial, how come this keyboard hook is so strange?! Please help. I really want to know why and how.
Posted on 2001-03-07 09:43:00 by zhanghz
The secret is in the value you return from your keyboard proc. Check your API reference under keyboard proc.
Posted on 2001-03-07 12:35:00 by me
i thought about it and i think the only way to interupt these msg's is to leave out further callnexthookex calls but i don't know if functions like getmessage or peekmessage retrieve msg's from the msgquene via hook... if not you can not do what you want to do. however, you CAN do it with tricks like api-patching or vxd's by the way, you said that you read icz's tut and mouse-hooks are simple to code but keyboard hook not - did you wrote a prog that catches all mouse events BEFORE they are transmited to some application? if yes then post it please but i think the answer is NOPE - keyboard hook are as easy as mouse hooks - if you just want to retrieve the keys some user pressed its an easy task but preventing other apps from retrieving these msg's is hard to do i think. ...or - maybe i am completly wrong : ) This message was edited by drcmda, on 3/7/2001 9:29:14 PM
Posted on 2001-03-07 21:23:00 by drcmda
Hi, me, I was careless and just found I need to return nonzero value in the hook procedure. It worked! Thank you!! But how can I disable all keyboard messages? Now I can still do "alt-tab", "windows" key, "caps lock" etc. Could you help again?
Posted on 2001-03-16 11:06:00 by zhanghz