Note that there are some explanatory texts on larger screens.

plurals
  1. POWINAPI's message loops drives me crazy
    text
    copied!<p>I've been trying to implement simple low level keyhook using JNI and all went well til I figured I can't call the methods while the DLL is on infinite loop(message loop). so I decided to create new thread but somehow, after I made it so the message loop runs on its own loop the lowlevel keyhook stops responding meaning that it doesn't call the keyproc anymore, and I got no idea why is this? is there any other work around for this? I am required to be able to call the DLL's methods while the keyboard hook is still functioning.</p> <p>My current code is as simple as</p> <p>register keyboard hook:</p> <pre><code>keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardProc, hInstance, 0); </code></pre> <p>start thread</p> <pre><code>HANDLE threadHandle = CreateThread(NULL, 0, ThreadProc, NULL, 0, &amp;threadId); </code></pre> <p>my keyboard proc and threadproc are the following:</p> <pre><code>DWORD WINAPI ThreadProc(LPVOID lpVoid) { MSG msg; while(GetMessage(&amp;msg, NULL, 0, 0)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } return 0; } LRESULT CALLBACK keyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { KBDLLHOOKSTRUCT keyEvent = *((KBDLLHOOKSTRUCT*)lParam); jint vkCode = keyEvent.vkCode; jint flags = keyEvent.flags; jint action = wParam; (*globalEnv).CallVoidMethod(globalObj, keyboardMethodId, vkCode, flags, action); return CallNextHookEx(NULL, nCode, wParam, lParam); } </code></pre> <p>where do I go wrong? I am sure it not the java as even if I add simple logging for the keyproc its never called. But if I stop using thread and run the message loop on main thread it works fine but DLL wont respond for method calls after it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload