Game Development Community

Problem of using SetWindowsHookEx function

by Nabarro · in Torque 3D Professional · 06/03/2012 (8:41 pm) · 3 replies

I came across one problem of function SetWindowsHookEx() when I took one trial by using T3D web deployment version source.

...
hHook = ::SetWindowsHookEx(WH_GETMESSAGE, GetMessageProc, WebCommon::gPluginModule, GetCurrentThreadId());
...
LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// If this is a keystrokes message, translate it in controls'
LPMSG lpMsg = (LPMSG) lParam;
if( (nCode >= 0) && PM_REMOVE == wParam/*
&& (lpMsg->message >= WM_KEYFIRST && lpMsg->message <= WM_KEYLAST) */)
{ ... }

...
}

When I use above codes, it can capture system key(WM_KEYDOWN, WM_KEYUP, etc) messages normally, but windows ATL(web deployment) can NOT capture IME related messages(which make it can't change Language Input Method.)

So I changed above codes like below:
hHook = ::SetWindowsHookEx(WH_CALLWNDPROC, GetMessageProc, WebCommon::gPluginModule, GetCurrentThreadId());
to make it capture WM_IME_SETCONTEXT, WM_IME_NOTIFY, WM_IME_COMPOSITION messages. It worked.

But, it can't capture system key messages(WM_KEYDOWN, WM_KEYUP, ...) now. I've tried to call ::SetWindowsHookEx() twice for hooking different functions, but it can't capture both key messages(WM_KEYDOWN, WM_KEYUP, ...) and IME messages(WM_IME_SETCONTEXT, ...) at the same time.

How to capture key messages and IME messages simultaneously? Is there something wrong when I use function ::SetWindowsHookEx()?

Anyone may help? Thanks...

#1
06/04/2012 (11:08 pm)
No one has used SetWindowsHookEx() function? Thanks,
#2
06/05/2012 (8:35 am)
I have not read on this topic, but it seems to me that the purpose of the IME is to intercept the keyboard for input and then the IME passes its composed data to the application. So I get the impression that you should not in fact be getting any input directly to your application while the IME is active.

I'm just guessing, but that's how I would expect it to behave.
#3
06/06/2012 (5:29 am)
Thank,
The problem is that I can't activate IME at all if I don't use below statements:

hHook = ::SetWindowsHookEx(WH_CALLWNDPROC, GetMessageProc, WebCommon::gPluginModule, GetCurrentThreadId()); (which captures WM_IME_SETCONTEXT, WM_IME_NOTIFY and WM_IME_COMPOSITION messages.)

If I use above statement, IME can be activated normally. But I can't delete my input words because WM_KEYDOWN/WM_KEYUP messages can't be captured.