Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following code hooks successfully of all open windows and applications on my desktop:
C#
IntPtr hInstance = LoadLibrary("User32.dll");
callbackDelegate = new HOOKPROC(HookCallback);
hhook = SetWindowsHookEx(WH_KEYBOARD_LL, callbackDelegate, hInstance, 0);

However, I would like to hook to a specific application/window (lets say Notepad), can it be done?
Posted
Updated 6-Dec-13 1:43am
v3

1 solution

No, there is no way to get messages directed at a specific application. Your hook code sits between the keyboard driver and the control with the input focus. Notice that there is no destination information in the data that is passed to your hook code. You have no idea where it's going and no way to find out.
 
Share this answer
 
Comments
Member 10436245 6-Dec-13 10:33am    
Thanks. But in that case, is it possible to listen to all events occurring on a specific application?
Dave Kreskowiak 6-Dec-13 11:06am    
The concepts of "events" only applies inside an application. It is the translation of a message into a branch of execution in your code.

There is a hook you can use, called CallWndProc[^], but the problem is that it cannot be used on another application from .NET. This is because .NET does not support the exports required to inject code into another process. You must write this hook code in C/C++.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900