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 :
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
KeyboardProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD invoke CallNextHookEx,hHook,nCode,wParam,lParam invoke PostMessage,hWnd,WM_KEYBOARDHOOK,wParam,0 xor eax,eax ret KeyboardProc endp
Up. Help please.
I'm not absolutely sure, but I think this will only trap keys going to your app. 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.
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.
The secret is in the value you return from your keyboard proc. Check your API reference under keyboard proc.
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
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?