public LowLevelMouseProc hookTheMouse() { return new LowLevelMouseProc() { public LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT info) { LRESULT result = USER32INST.CallNextHookEx(hhk, nCode, wParam, new WinDef.LPARAM(Pointer.nativeValue(info.getPointer()))); if (nCode >= 0) { int action = wParam.intValue(); // System.out.println(action); switch (action) { case WM_LBUTTONDOWN: // do stuff break; case WM_RBUTTONDOWN: WindowsXPMouse.action.run(); break; case WM_MBUTTONDOWN: // do other stuff break; case WM_LBUTTONUP: WindowsXPMouse.action.run(); break; case WM_MOUSEMOVE: break; default: break; } /**************************** DO NOT CHANGE, this code unhooks mouse *********************************/ if (threadFinish == true) { // System.out.println("post quit"); USER32INST.PostQuitMessage(0); } /*************************** END OF UNCHANGABLE *******************************************************/ } return result; } }; }
public LRESULT callback(int nCode, WPARAM wParam, LPARAM lParam) { System.err.println("callback bbbnhkilhjkibh nCode: " + nCode); return new LRESULT(0); }
public void initKeyHook() { thread = new Thread(new Runnable() { @Override public void run() { final User32 lib = User32.INSTANCE; HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null); keyboardHook = new LowLevelKeyboardProc() { public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) { if (nCode >= 0) { switch (wParam.intValue()) { // case WinUser.WM_KEYUP: case WinUser.WM_KEYDOWN: // case WinUser.WM_SYSKEYUP: case WinUser.WM_SYSKEYDOWN: // do active userActive(); } } return lib.CallNextHookEx(hhk, nCode, wParam, info.getPointer()); } }; hhk = lib.SetWindowsHookEx(WinUser.WH_KEYBOARD_LL, keyboardHook, hMod, 0); // This bit never returns from GetMessage int result; MSG msg = new MSG(); while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) { if (result == -1) { System.err.println("error in get message"); break; } else { System.err.println("got message"); lib.TranslateMessage(msg); lib.DispatchMessage(msg); } } lib.UnhookWindowsHookEx(hhk); } }); thread.start(); }
/** * @param hwnd [in] Type: HWND * * A handle to the window. * * @param uMsg [in] Type: UINT * * The message. * * For lists of the system-provided messages, see System-Defined * Messages. * * @param wParam [in] Type: WPARAM * * Additional message information. The contents of this parameter depend * on the value of the uMsg parameter. * * @param lParam [in] Type: LPARAM * * Additional message information. The contents of this parameter depend * on the value of the uMsg parameter. * * @return the lresult */ LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam);
/** * An application-defined function that processes messages sent * to a window. * * @param hwnd A handle to the window. * @param uMsg The message. * @param wParam Additional message information. * @param lParam Additional message information. * @return The result of the message processing and depends on * the message sent */ LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam);
LRESULT DefWindowProc(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
LRESULT SetWindowLong(HWND hwnd, int index, WindowProc newProc);
LRESULT SetWindowLongPtr(HWND hwnd, int index, WindowProc newProc);
LRESULT DispatchMessage(MSG msg);
LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
public LRESULT SendMessage(HWND hwnd, int msg, WPARAM wParam, LPARAM lParam);
LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT lParam);
public LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT lParam);