There's a working example of the keyboard hook in svn under the
"contrib" directory.
On Aug 27, 2008, at 12:44 PM, Alan Snyder wrote:
Thanks for the response to the previous question. I'm trying to
create hooks
for global mouse and keyboard events on both Mac and PC. Currently
working
on the keyboard part for the PC and do have questions about using
JNA here.
I'm trying to install a hook using
SetWindowsHookEx(WH_KEYBOARD_LL, ....
but need to understand if the callback can be entirely in JNA or
does it
need to be in a separate DLL. If it can be entirely in JNA then what
do you set
HINSTANCE to? Also what should be the returned LRESULT value?
Here is what I have. It doesn't crash in any way, but neither does
it respond to any
keyboard events. (This is using the User32 call in JNA 3.0.5)
final User32 user32 = User32.INSTANCE;
HINSTANCE hInst =
Kernel32.INSTANCE.GetModuleHandle(null);//?What is this really?;
HHOOK hHook =
user32.SetWindowsHookEx(User32.WH_KEYBOARD_LL, new
User32.LowLevelKeyboardProc() {
public LRESULT callback(int nCode, WPARAM wParam,
KBDLLHOOKSTRUCT lParam) {
System.out.println("nCode="+nCode);//Just print
something to confirm the callback
//What should we return from here? Zero?
CallNextHookEx?;
return new LRESULT(0);
}
}, hInst, 0);
I did see a similar thread back in Nov. 2007 on this not the
conclusion. Any advise is appreciated.