I was messing around with hooks and thought I'd make a crude lil key logger. The thing is, it works fine for my window, but no others. The keyboard proc is in its own dll. This is the keyboard proc:

KeyboardProc proc nCode:DWORD, wParam:WPARAM, lParam:LPARAM

.IF nCode == HC_ACTION
; Only bother with key up and repeat messages
; Transition state flags are in the high word of lParam
mov eax, lParam
shr eax, 16
.IF (ax & KF_UP || ax & KF_REPEAT)
; Send a message to my window
[COLOR=red]; invoke MessageBox, NULL, NULL, NULL, MB_OK[/COLOR]
invoke PostMessage, hWnd, WM_KEYHOOK, NULL, NULL

; Pass this to the rest of the hook chain
invoke CallNextHookEx, hHook, nCode, wParam, lParam
KeyboardProc endp

My window never recieves anything if it doesn't have the focus. But if I uncomment the messagebox call (in red), no matter what window has focus, the message box appears (meaning my dll did in fact pick up all events). My question is, why isn't my window getting messages all the time? :confused:
Posted on 2002-12-20 20:53:21 by Miko
are you sure the hWnd your posting the message to is your program? perhaps when the window loses focus the hwnd changes and you are posting messages to the new window. that would explain the messagebox showing, but the messages not being processed by your window...
Posted on 2002-12-20 21:22:54 by saderax
I guessed that, but I wouldn't have any idea why hWnd would change. It's set when my program installs the hook, calling this (passes its handle as hWin, and the dll stores it under hWnd). Nothing else inside the DLL affects the value of hWnd.

InstallHook proc hWin:DWORD
push hWin
pop hWnd
invoke SetWindowsHookEx, WH_KEYBOARD, ADDR KeyboardProc, hInstance, NULL
mov hHook, eax
InstallHook endp
Posted on 2002-12-20 21:43:28 by Miko
Posted on 2002-12-21 04:54:07 by Four-F
omg I must be blind. I always search the board before. Maybe I'm just becoming senile :/

Thanks Four-F
Posted on 2002-12-21 11:07:14 by Miko