Getting button clicks from other windows

BlitzPlus Forums/BlitzPlus Programming/Getting button clicks from other windows

RifRaf(Posted 2007) [#1]
Is there any way using User32 or another dll to determine what buttons are hit in another application.

If you know how to do this, example code would be greatly appreciated as well. Thanks in advance.


Kev(Posted 2007) [#2]
Hi RifRaf

It can be done but you would need an external .dll to hook the other application's window proc, this would be somthing like this.

first you would need to obtain the application's processId using GetWindowThreadProcessId() then call SetWindowsHookEx() using the message WH_CALLWNDPROC and using the returned pocessid.

ie
HHOOK gHook = SetWindowsHookEx(WH_CALLWNDPROC,GLOBAL_HOOKED_MESSAGE_WINPROC_2,0,GetWindowThreadProcessId(hwnd,NULL));


GLOBAL_HOOKED_MESSAGE_WINPROC is callback function that will handle the messages before your HOOKED application would process them.

this would look like somthing like this

LRESULT CALLBACK GLOBAL_HOOKED_MESSAGE_WINPROC_2(int code,WPARAM wParam,LPARAM lParam){
        if(code<<HC_ACTION){
                return CallNextHookEx(gHook,code,wParam,lParam);
        }else{
                CWPSTRUCT *msg = (CWPSTRUCT*)lParam;
                switch(msg->message){              

                }
        }
}


this would need to be handled using .dll calls from within blitzplus, once finshed a call to UnhookWindowsHookEx() would be needed.

kev