np.
np.

Reputation: 49

Windows API: handling keypress event of external window application through C#

I have one external application window opened. Through my winform application, i want to execute certain code when keypress event happens on this external window.

I know window handle of this external application window.

Any help will be truely appreciated.

Thanks,

Upvotes: 3

Views: 3305

Answers (1)

Xavier Poinas
Xavier Poinas

Reputation: 19733

One way to do this is to set up a hook on the external application window with SetWindowHookEx. Then monitor the WM_KEYDOWN message.

I am actually not sure that it will work in C# because the hook callback has to be in a native DLL. You might have to write a portion of the solution in an unmanaged language.

Alternatively, you could use a global keyboard hook, possibly combined with a check of the currently active window.

Upvotes: 2

Related Questions